Reply to topic  [ 3 posts ] 
ExceptionInvalid position for the last cell!! 
Author Message

Joined: Tue May 22, 2007 11:07 pm
Posts: 2
Reply with quote
Post 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();
}

}


Thu May 24, 2007 3:30 pm
Profile

Joined: Fri Feb 03, 2006 12:23 pm
Posts: 199
Location: Brasov, Romania
Reply with quote
Post 
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


Last edited by daniela on Tue Sep 25, 2007 6:31 am, edited 1 time in total.



Mon May 28, 2007 3:54 am
Profile WWW

Joined: Tue May 22, 2007 11:07 pm
Posts: 2
Reply with quote
Post 
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);


Mon May 28, 2007 10:33 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.