EasyXLS
http://forum.easyxls.com/

ExceptionInvalid position for the last cell!!
http://forum.easyxls.com/viewtopic.php?f=4&t=49
Page 1 of 1

Author:  ivanpedruzzi [ Thu May 24, 2007 3:30 pm ]
Post subject:  ExceptionInvalid position for the last cell!!

I am getting the the fallowing exception with a sample Java program I wrote for evaluation purpose. Please contact me at ipedruzz@datadirect.com and i will provide the xls files

java.lang.Exception: Invalid position for the last cell!!
at EasyXLS.ExcelDocument.a(SourceFile:4506)
at EasyXLS.ExcelDocument.a(SourceFile:4974)
at EasyXLS.ExcelDocument.a(SourceFile:4968)
at EasyXLS.ExcelDocument.easy_ReadExcelWorksheet_AsXML(SourceFile:4874)
at testexceljava.XLS.toXML(XLS.java:34)

In the same test application i am trying to export the excel file to XML but the result is not well formed

We are really intrigued by your product.
Ivan Pedruzzi




package testexceljava;

import java.io.FileInputStream;
import javax.xml.parsers.*;

import EasyXLS.*;

public class XLS {

public static void main(String[] args)throws Exception
{
try{
toXML("C:\\Samples\\books.xls");
}catch(Exception e){
e.printStackTrace();
}
toXML("C:\\Samples\\dr.xls");
System.out.println("done!");
}

static void toXML(String xslpath) throws Exception
{
System.out.println("Start " + xslpath);
ExcelDocument xls = new ExcelDocument();
String xmlpath = xslpath + ".xml";
FileInputStream file = new FileInputStream(xslpath);
xls.easy_LoadTemplateFile(file);
xls.easy_WriteXMLFile(xmlpath);

for (int i=0; i < xls.SheetCount(); i++){
ExcelWorksheet ws = (ExcelWorksheet)xls.easy_getSheetAt(i);
String xmlsheetpath = xslpath + "_" + ws.getSheetName() + ".xml";
System.out.println("Start " + xmlsheetpath);
xls.easy_ReadExcelWorksheet_AsXML(xmlsheetpath, ws);
System.out.println("Finished " + xmlsheetpath);
}

file.close();

System.out.println("Finished " + xslpath);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
builder.parse(xmlpath);
xls.Dispose();
}

}

Author:  daniela [ Mon May 28, 2007 3:54 am ]
Post subject: 

The exception is caused by the empty sheets from your document. To avoid the error we suggest you to skip the generation of the empty sheets:

for (int i=0; i < xls.SheetCount(); i++){
ExcelWorksheet ws = (ExcelWorksheet)xls.easy_getSheetAt(i);
<b> if (ws.easy_getExcelTable().RowCount() != 0){</b>
String xmlsheetpath = xslpath + "_" + ws.getSheetName() + ".xml";
System.out.println("Start " + xmlsheetpath);
xls.easy_ReadExcelWorksheet_AsXML(xmlsheetpath, ws);
System.out.println("Finished " + xmlsheetpath);
}
}

The result of the XML is well formatted. When exporting a sheet to xml format, only the data is exported in the xml file. The xml file format is not the XML Spreadsheet file format, as in your first export, it is a different format. The xml schema for this format can be found at:
http://www.easyxls.com/manual/html/pr ... iveXLS.xsd

Other useful information about EasyXLS and XML can be found in the User Guide:
http://www.easyxls.com/manual/index.html
chapters:
EasyXLS Basics/Import Files/Import from XML Files and
EasyXLS Basics/Export Files/Export XML Files

Author:  ivanpedruzzi [ Mon May 28, 2007 10:33 am ]
Post subject: 

Daniela,

The fact the two functions generates two different XML formats is irrelevant.

The point is that the following instructions generate a XML Spreadsheet document that is not well formed therefore cannot be parsed.

The element type "Panes" must be terminated by the matching end-tag "</Panes>".


ExcelDocument xls = new ExcelDocument();
FileInputStream file = new FileInputStream(("C:\\Samples\\dr.xls");
xls.easy_LoadTemplateFile(file);
xls.easy_WriteXMLFile(xmlpath);

Page 1 of 1 All times are UTC - 4 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/