I am having problems with HSSFWorkbook changing (corrupting) Excel files.
Using the following code (Please let me know if I am doing anything wrong
here!):
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
//import org.apache.poi.hssf.dev.BiffViewer;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class LoadAndSaveExcel {
public static void main(String[] args) {
String newFileName = "";
try {
String fileName = "Ok3.xls";
newFileName = "Saved_" + fileName;
URL url = new URL("File:C:/" + fileName);
//String bifArgs[] = {"C:\\" + fileName};
//BiffViewer bv = new BiffViewer(bifArgs);
//bv.run();
URLConnection uc = url.openConnection();
InputStream inputStream = uc.getInputStream();
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(inputStream)
;;
hssfWorkbook.write(new FileOutputStream("C:\\" +
newFileName));
} catch (IOException exc) {
System.out.println(exc.getMessage());
}
System.out.println("Done File = " + "C:\\" + newFileName);
}
}
I end up with a file where many formulas are changed. For example in tab
"Nodes in nodes" cell C2 the formular is changed from
=INDIREKTE(ADRESSE(KOLONNE();1;;;"Node Types"))
to
=INDIREKTE(ADRESSE(KOLONNE();1;;;"Port Types"))
I have attached two files
1. Ok3.xls the file I am reading in
http://www.nabble.com/file/p15613196/ok3.xls ok3.xls
2. Save_Ok3.xls the file after it has been saved (corrupted) by the above
Java program.
http://www.nabble.com/file/p15613196/Saved_Ok3.xls Saved_Ok3.xls
I have also attached a very similar start file Ok4.xls which doesn't show
the problem
http://www.nabble.com/file/p15613196/ok4.xls ok4.xls
In this last file I have deleted a lot of unnecessary cells (apparently
blank!).
I have over 150 source Excel files that show this behaviour so a manual edit
of them all will take weeks :-(
--
View this message in context:
http://www.nabble.com/HSSFWorkbook.write-corrupting-Excel-files-tp15613196p15613196.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]