我是用POI导出excel的,现在要将刚导出的excel再导入,可是导入时POI里对很对格式要求是比较严格的,如日期型,会直接读成数字。所以后来改成用jxl来导入。但导入时又会弹出警告:
Warning: Some cells exceeded the specified bounds. Resizing sheet dimensions from 9x6 to 10x6不知哪位大侠有遇到相同的问题,是如何解决的!
Warning: Some cells exceeded the specified bounds. Resizing sheet dimensions from 9x6 to 10x6不知哪位大侠有遇到相同的问题,是如何解决的!
from 9x6 to 10x6 估计是的
/9789577568267 民事訴訟法測驗題庫體系書2V59 380 380 1 T A0011 0.81 I1 A0011
--------------------------------------------
以上是excel档中的内容;不存在合并单元格,不存在日期,这次警告是:
Warning: Some cells exceeded the specified bounds. Resizing sheet dimensions from 9x2 to 10x2
from 9x2 to 10x2 ----》I1 A0011请大家再帮忙看看啊!
* <p>Title:Excel文档输出 </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import java.io.IOException;
import java.util.Hashtable;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.Region;
import twf.general.Util;public class ExcelOut extends HttpServlet
{ private Hashtable styleht; public ExcelOut()
{
styleht = null;
}
//页面请求
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String excelfile = Util.null2String(req.getParameter("excelfile"));
ExcelFile ef = null;
ExcelSheet sheetvalues = null;
ExcelRow rowvalues = null;
HSSFWorkbook wb = null;
HSSFSheet sheets = null;
HSSFRow rows = null;
HSSFCell cells = null;
HSSFCellStyle cellStyle = null;
if(excelfile.equals(""))
ef = (ExcelFile)req.getSession(true).getAttribute("ExcelFile");
else
ef = (ExcelFile)req.getSession(true).getAttribute(excelfile);
if(ef == null)
return;
wb = new HSSFWorkbook();
initStyle(ef, wb);
int sheetindex = 0;
while(ef.next())
{
String sheetname = ef.getSheetname();
sheetvalues = ef.getSheet();
if(sheetvalues != null)
{
sheets = wb.createSheet();
wb.setSheetName(sheetindex, Util.fromScreen(sheetname), (short)1);
sheetindex++;
for(int i = 0; i < sheetvalues.size(); i++)
{
rowvalues = sheetvalues.getExcelRow(i);
if(rowvalues != null)
{
short rowheight = rowvalues.getHight();
rows = sheets.createRow((short)i);
if(rowheight != 255)
rows.setHeightInPoints(rowheight);
int rowcellindex = 0;
boolean hasstyle = false;
boolean hasspan = false;
if(rowvalues.stylesize() == rowvalues.size())
hasstyle = true;
if(rowvalues.spansize() == rowvalues.size())
hasspan = true;
for(int j = 0; j < rowvalues.size(); j++)
{
cells = rows.createCell((short)rowcellindex);
String cellvalues = Util.null2String(rowvalues.getValue(j));
String cellvalueh = cellvalues.substring(0, 2);
String cellvaluev = cellvalues.substring(2);
if(cellvalueh.indexOf("s_") == 0)
{
cells.setEncoding((short)1);
cells.setCellValue(Util.fromHtmlToEdit(cellvaluev));
} else
if(cellvalueh.indexOf("i_") == 0)
{
int tempvalue = Util.getIntValue(cellvaluev);
if(tempvalue != 0)
cells.setCellValue(tempvalue);
} else
if(cellvalueh.indexOf("f_") == 0)
{
float tempvalue = Util.getFloatValue(cellvaluev);
if((double)tempvalue != 0.0D)
cells.setCellValue(tempvalue);
} else
if(cellvalueh.indexOf("d_") == 0)
{
double tempvalue = Util.getDoubleValue(cellvaluev);
if(tempvalue != 0.0D)
cells.setCellValue(tempvalue);
} else
if(cellvalueh.indexOf("o_") == 0)
cells.setCellFormula(cellvaluev);
else
if(cellvalueh.indexOf("n_") == 0)
if(Util.getDoubleValue(cellvaluev, -9999.9899999999998D) == -9999.9899999999998D)
{
cells.setEncoding((short)1);
cells.setCellValue(Util.fromHtmlToEdit(cellvaluev));
} else
{
double tempvalue = Util.getDoubleValue(cellvaluev);
if(tempvalue != 0.0D)
cells.setCellValue(tempvalue);
}
if(hasstyle)
{
String stylename = Util.null2String(rowvalues.getStyle(j));
if(!stylename.equals(""))
{
cellStyle = getStyle(stylename);
if(cellStyle != null)
cells.setCellStyle(cellStyle);
}
}
if(hasspan)
{
int rowspan = rowvalues.getSpan(j);
if(rowspan > 1)
{
for(int k = 0; k < rowspan - 1; k++)
{
rowcellindex++;
cells = rows.createCell((short)rowcellindex);
cells.setCellValue("");
if(hasstyle && cellStyle != null)
cells.setCellStyle(cellStyle);
} sheets.addMergedRegion(new Region(i, (short)((rowcellindex + 1) - rowspan), i, (short)rowcellindex));
}
}
rowcellindex++;
} }
} for(int i = 0; i < sheetvalues.columnsize(); i++)
sheets.setColumnWidth((short)i, sheetvalues.getColumnwidth(i)); }
}
String filename = ef.getFilename();
res.setHeader("content-disposition", "attachment; filename=" + filename);
ServletOutputStream out = res.getOutputStream();
res.setContentType("application/octet-stream");
wb.write(out);
out.flush();
out.close();
} private void initStyle(ExcelFile ef, HSSFWorkbook wb)
{
styleht = new Hashtable();
HSSFCellStyle cellStyle = null;
HSSFFont thefont = null;
while(ef.nextStyle())
{
String stylename = ef.getStyleName();
ExcelStyle est = ef.getStyleValue();
if(est != null)
{
cellStyle = wb.createCellStyle();
thefont = wb.createFont();
if(est.getGroundcolor() != 9)
{
cellStyle.setFillPattern((short)1);
cellStyle.setFillForegroundColor(est.getGroundcolor());
}
cellStyle.setRotation(est.getScale());
if(est.getAlign() != 10)
cellStyle.setAlignment(est.getAlign());
if(est.getDataformart() != 0)
cellStyle.setDataFormat(est.getDataformart());
cellStyle.setVerticalAlignment(est.getValign());
thefont.setColor(est.getFontcolor());
thefont.setBoldweight(est.getFontbold());
thefont.setFontHeightInPoints(est.getFontheight());
cellStyle.setFont(thefont);
styleht.put(stylename, cellStyle);
}
}
} private HSSFCellStyle getStyle(String stylename)
{
return (HSSFCellStyle)styleht.get(stylename);
}
}
package twf.file;/**
* <p>Title:Excel文档输出 </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006 </p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import java.io.IOException;
import java.util.Hashtable;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.Region;
import twf.general.Util;public class ExcelOut extends HttpServlet
{ private Hashtable styleht; public ExcelOut()
{
styleht = null;
}
//页面请求
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String excelfile = Util.null2String(req.getParameter("excelfile"));
ExcelFile ef = null;
ExcelSheet sheetvalues = null;
ExcelRow rowvalues = null;
HSSFWorkbook wb = null;
HSSFSheet sheets = null;
HSSFRow rows = null;
HSSFCell cells = null;
HSSFCellStyle cellStyle = null;
if(excelfile.equals(""))
ef = (ExcelFile)req.getSession(true).getAttribute("ExcelFile");
else
ef = (ExcelFile)req.getSession(true).getAttribute(excelfile);
if(ef == null)
return;
wb = new HSSFWorkbook();
initStyle(ef, wb);
int sheetindex = 0;
while(ef.next())
{
String sheetname = ef.getSheetname();
sheetvalues = ef.getSheet();
if(sheetvalues != null)
{
sheets = wb.createSheet();
wb.setSheetName(sheetindex, Util.fromScreen(sheetname), (short)1);
sheetindex++;
for(int i = 0; i < sheetvalues.size(); i++)
{
rowvalues = sheetvalues.getExcelRow(i);
if(rowvalues != null)
{
short rowheight = rowvalues.getHight();
rows = sheets.createRow((short)i);
if(rowheight != 255)
rows.setHeightInPoints(rowheight);
int rowcellindex = 0;
boolean hasstyle = false;
boolean hasspan = false;
if(rowvalues.stylesize() == rowvalues.size())
hasstyle = true;
if(rowvalues.spansize() == rowvalues.size())
hasspan = true;
for(int j = 0; j < rowvalues.size(); j++)
{
cells = rows.createCell((short)rowcellindex);
String cellvalues = Util.null2String(rowvalues.getValue(j));
String cellvalueh = cellvalues.substring(0, 2);
String cellvaluev = cellvalues.substring(2);
if(cellvalueh.indexOf("s_") == 0)
{
cells.setEncoding((short)1);
cells.setCellValue(Util.fromHtmlToEdit(cellvaluev));
} else
if(cellvalueh.indexOf("i_") == 0)
{
int tempvalue = Util.getIntValue(cellvaluev);
if(tempvalue != 0)
cells.setCellValue(tempvalue);
} else
if(cellvalueh.indexOf("f_") == 0)
{
float tempvalue = Util.getFloatValue(cellvaluev);
if((double)tempvalue != 0.0D)
cells.setCellValue(tempvalue);
} else
if(cellvalueh.indexOf("d_") == 0)
{
double tempvalue = Util.getDoubleValue(cellvaluev);
if(tempvalue != 0.0D)
cells.setCellValue(tempvalue);
} else
if(cellvalueh.indexOf("o_") == 0)
cells.setCellFormula(cellvaluev);
else
if(cellvalueh.indexOf("n_") == 0)
if(Util.getDoubleValue(cellvaluev, -9999.9899999999998D) == -9999.9899999999998D)
{
cells.setEncoding((short)1);
cells.setCellValue(Util.fromHtmlToEdit(cellvaluev));
} else
{
double tempvalue = Util.getDoubleValue(cellvaluev);
if(tempvalue != 0.0D)
cells.setCellValue(tempvalue);
}
if(hasstyle)
{
String stylename = Util.null2String(rowvalues.getStyle(j));
if(!stylename.equals(""))
{
cellStyle = getStyle(stylename);
if(cellStyle != null)
cells.setCellStyle(cellStyle);
}
}
if(hasspan)
{
int rowspan = rowvalues.getSpan(j);
if(rowspan > 1)
{
for(int k = 0; k < rowspan - 1; k++)
{
rowcellindex++;
cells = rows.createCell((short)rowcellindex);
cells.setCellValue("");
if(hasstyle && cellStyle != null)
cells.setCellStyle(cellStyle);
} sheets.addMergedRegion(new Region(i, (short)((rowcellindex + 1) - rowspan), i, (short)rowcellindex));
}
}
rowcellindex++;
} }
} for(int i = 0; i < sheetvalues.columnsize(); i++)
sheets.setColumnWidth((short)i, sheetvalues.getColumnwidth(i)); }
}
String filename = ef.getFilename();
res.setHeader("content-disposition", "attachment; filename=" + filename);
ServletOutputStream out = res.getOutputStream();
res.setContentType("application/octet-stream");
wb.write(out);
out.flush();
out.close();
} private void initStyle(ExcelFile ef, HSSFWorkbook wb)
{
styleht = new Hashtable();
HSSFCellStyle cellStyle = null;
HSSFFont thefont = null;
while(ef.nextStyle())
{
String stylename = ef.getStyleName();
ExcelStyle est = ef.getStyleValue();
if(est != null)
{
cellStyle = wb.createCellStyle();
thefont = wb.createFont();
if(est.getGroundcolor() != 9)
{
cellStyle.setFillPattern((short)1);
cellStyle.setFillForegroundColor(est.getGroundcolor());
}
cellStyle.setRotation(est.getScale());
if(est.getAlign() != 10)
cellStyle.setAlignment(est.getAlign());
if(est.getDataformart() != 0)
cellStyle.setDataFormat(est.getDataformart());
cellStyle.setVerticalAlignment(est.getValign());
thefont.setColor(est.getFontcolor());
thefont.setBoldweight(est.getFontbold());
thefont.setFontHeightInPoints(est.getFontheight());
cellStyle.setFont(thefont);
styleht.put(stylename, cellStyle);
}
}
} private HSSFCellStyle getStyle(String stylename)
{
return (HSSFCellStyle)styleht.get(stylename);
}
}