2013年9月10日星期二

About jxl export excel "File error that may have lost some of thedata format "

This is two days doing a statistical report , with jxl export excel file, open the file , always pop up a message box saying " file error , you may have lost some of the data format ." Depressed for a long time, has not found solutions, Internet search, find many information , some say excel template version of the problem, but I tried 2007, 2003 , or save it as 97-2000 , I have tried, but or useless , hoping Which predecessors , experts encountered a favor ! !
------ Solution ---------------------------------------- ----
landlord I tried it , I guess it should be a problem jxl library .

solution.

excel () method in
WritableWorkbook wwb = wb.createWorkbook (baos, wb); phrase into the following three .

WorkbookSettings settings = new WorkbookSettings (); 
settings.setWriteAccess(null);
WritableWorkbook wwb = wb.createWorkbook(baos, wb, settings);

http://blog.csdn.net/deng11342/article/details/7479136


------ For reference only ---------------------------------- -----
paste the code look ?
Or use poi try.
------ For reference only -------------------------------------- -


This is what I do in the dormitory test code :
@ Override
protected void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType ("application / msexcel; charset = GBK");
res.setHeader ("Content-Disposition", "attachment; filename =" +
"aa.xls");

InputStream in = this.excel ();
OutputStream out = res.getOutputStream ();
byte [] b = new byte [1024];
int i = 0;
while ((i = in.read (b))> = 0) {
out.write (b, 0, i);
}
out.flush ();
in.close ();
out.close ();
}

public InputStream excel () {
List list = new ArrayList ();
list.add ("one");
list.add ("one");
list.add ("one");
list.add ("two");
int x = 0; / / write from the first few lines

File file = new File ("D :/ / 22.xls"); / / template file
try {
Workbook wb = Workbook.getWorkbook (file);
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
WritableWorkbook wwb = wb.createWorkbook (baos, wb);
WritableSheet sheet = wwb.getSheet (0);
for (int i = 0; i Object value = list.get (i);
sheet.addCell (new Label (i, x, list.get (i)));

}

wwb.write ();
wb.close ();
wwb.close ();
return new ByteArrayInputStream (baos.toByteArray ());
} catch (Exception e) {
e.printStackTrace ();
}
return null;
}
------ For reference only --------------------------------- ------

buddy ! That way you can do ? I tried it , or not ! But thank you ! !
------ For reference only -------------------------------------- -
true or not, no one can explain it to write a proper
------ For reference only --------------------- ------------------
I have encountered this problem, but I just did a little test , have found the problem , it is best to use the 2003 template , and then in 2003 which modify the template can not be 2003 or 2010 and then in 2007 to modify the inside , so that will not work, or when exported will complain , and you use 2003 as a template to modify the exported after a good try, I just tested already, because I was 2003 before the template, and then the machine installed in 2010 , and on this unit to modify the template , and then export the file data format , they reported missing
----- - For reference only ---------------------------------------
ask how to solve I have encountered, upstairs methods are tried or a problem. Find a sample , the easiest export import templates , no problem. I put the sample code and jxl package into my project where there are problems . What really can not think why. And other packages will be because of conflict? Such as poi what ?
Workbook wb = Workbook.getWorkbook (new File ("C: \ \ Users \ \ Desktop \ \ JExcel \ \ JExcel \ \ Template.xls"));

WritableWorkbook book = Workbook.createWorkbook (new File ("C: \ \ Users \ \ Desktop \ \ JExcel \ \ JExcel \ \ NV1.xls"), wb);
book.write ();
book.close ();
wb.close ();
------ For reference only ---------------------------- -----------
I just installed a 2003 special , but not, although files can be displayed properly , it can normally be used, but are prompted each time you open that , I feel very uncomfortable

1 条评论:

  1. Flowers from florists can be so expensive, and it is so
    easy to get flowers that look just as nice but cost so much less.

    Keep an eye out for online flower delivery specials with this one, since
    they change weekly. Good florists offer excellent flower delivery services.


    My website; flowers online

    回复删除