English 中文(简体)
JSP response content type Excel
原标题:

when i set response content type is excel. In excel sheet it is dsiplaying 1-Jan instead-of 1-1. here is code snippet

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

<%
    response.setContentType("application/vnd.ms-excel");
%>
<table><tr><td>1-1</td></tr></table>

Appending single quote " " will work. is there any other solution to set cell format or correct text?

问题回答

You could use the Apache POI project to return an Excel file to the output stream, which will allow you to do proper data/cell formatting.

See http://poi.apache.org/

Would that work for you?

You re fooling the webbrowser and Excel with a plain HTML table with a wrong content type and you re complaining that it doesn t work well in Excel due to an Excel-specific behaviour?

That doesn t sound right.

If you want an Excel file, create a real Excel file, not a plain HTML table along with a wrong content type. You can use the aforementioned Apache POI HSSF or Andy Khan s JExcelAPI for this.

As an alternative you can always go ahead with CSV. Less opaque and more easy. You can find here an example I recently posted: JSP page without HTML code for exporting data to Excel Sheet

I got quick workqround is

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%
    response.setContentType("application/vnd.ms-excel");
%>
<table>
<tr><td style= mso-number-format:"@"; >1-1< /td></tr>
</table>

We are planning to use poi api.

Thanks to all.





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签