日期:2014-05-18  浏览次数:20670 次

excel导出问题
我采用的最简单的方式,response.setContentType( "application/vnd.ms-excel;charset=GBK ");但是导出的数据中000000变成了0,怎么能让导出的数据仍然显示为000000。不知道这是excel自身的问题,还是可以通过程序实现。因为在excel中输入000000,自动也会给变成0。哪位大虾帮忙解决解决

------解决方案--------------------
將EXCEL中 "數值 "改為 "字母 "模式..
------解决方案--------------------
可能需要通过程序把excel设置某列为字符型
------解决方案--------------------
将表格的属性改为“字符”。
------解决方案--------------------
用jxl.jar这个jar包,网上找找有,然后把字段改成text型,jxl实例
package infon.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcel {
public void InputExcel(String path) {
try {
InputStream is = new FileInputStream(path);
Workbook wb = Workbook.getWorkbook(is);
int sheetCount = wb.getNumberOfSheets();
System.out.println( "count of page: " + sheetCount);
for (int s = 0; s < sheetCount; s++) {
Sheet st = wb.getSheet(s);
int column = st.getColumns();
int row = st.getRows();
System.out.println( "page name: " + st.getName() + "\n column: "
+ column + "\n row: " + row);
Cell cell = null;
for (int m = 0; m < column; m++) {
for (int n = 0; n < row; n++) {
cell = st.getCell(m, n);
System.out.print(cell.getContents() + " ");
}
System.out.println();
}
}
wb.close();
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
new ReadExcel()
.InputExcel( "test.xls ");
}
}
package infon.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcel {
public void InputExcel(String path) {
try {
InputStream is = new FileInputStream(path);
Workbook wb = Workbook.getWorkbook(is);
int sheetCount = wb.getNumberOfSheets();
System.out.println( "count of page: " + sheetCount);
for (int s = 0; s < sheetCount; s++) {
Sheet st = wb.getSheet(s);
int column = st.getColumns();
int row = st.getRows();
System.out.println( "page name: " + st.getName() + "\n column: "
+ column + "\n row: " + row);
Cell cell = null;
for (int m = 0; m < column; m++) {
for (int n = 0; n < row; n++) {
cell = st.getCell(m, n);
System.out.print(cell.getContents() + " ");
}
System.out.println();