Hello Des,

Are you forced to use XLS2CXV for some reason? As Nick said in one of his 
replies you can very quickly code a simple routine using the usermodel's 
classes that will convert a spreadsheet file into CSV. To give you a start, the 
pseudocode would be something like;

Open a workbook;
For each sheet in the workbook
For each row in the sheet
For each cell in the row
Get the contents of the cell and write to file
Next cell
Next row
Next sheet

When you get a cell, all you need to do is find out it's type and then call the 
appropriate method to recover that cell's contents. This can then be converted 
into a String - if necessary - and concatenated using the StringBuffer class 
most likely to create a row that you can write to the output CSV file.

--- On Tue, 12/9/08, Des Hartman <[EMAIL PROTECTED]> wrote:
From: Des Hartman <[EMAIL PROTECTED]>
Subject: Re: HSSF Formula not parsing String folumas
To: "POI Users List" <[email protected]>
Date: Tuesday, December 9, 2008, 6:15 PM

I did an ugly hack to try and force the next record be printed and it
worked, but I get some unwelcome results as well.

Here's what I see and what I did:

1) The "if(Double.isNaN( frec.getValue() ))" statement inside the
"case
FormulaRecord.sid:" does not properly decode the String formula and as a
result thinks it is a number (0.0 in this case. Because of this
outputNextStringRecord is never set to true and thus the formula is never
printed out in the next iteration.

2) To overcome this, I simply commented out all the logic and forced the
outputNextStringRecord = true to always execute. This now prints out the
String formula, but there are other issues now in that the formatting and
the actual formula is screwed up.

This is what I commented out:

        case FormulaRecord.sid:
            // Cast record
///            System.out.println("Formula Record");
            FormulaRecord frec = (FormulaRecord) record;

            thisRow = frec.getRow();
            thisColumn = frec.getColumn();

///            if(outputFormulaValues) {
///                if(Double.isNaN( frec.getValue() )) {
                    // Formula result is a string
                    // This is stored in the next record
                    outputNextStringRecord = true;
                    nextRow = frec.getRow();
                    nextColumn = frec.getColumn();
///                } else {
///                    thisStr = formatListener.formatNumberDateCell(frec);
///                }
///            } else {
///                thisStr = '"' +
///                    HSSFFormulaParser.toFormulaString(stubWorkbook,
frec.getParsedExpression()) + '"';
///            }
            break;

This is what the result is running the file now:


Sheet1 [1]:
"A","B"
,AB,,,"C"

Sheet2 [2]:

Sheet3 [3]:


As you can see there is a line return after "B". This is because for
some
reason the routine now thinks it has reached an end of a row after finding
the formula value????.

There are also two additional ",," before the "C" value.


>From this it definitely looks like there is something broken in the file.
would you be able to comment or point me in the right direction?

Thanks
Des



2008/12/9 Nick Burch <[EMAIL PROTECTED]>

> On Tue, 9 Dec 2008, Des Hartman wrote:
>
>> I am using XLS2CSVmra to parse a very simple XLS file, but I am
getting
>> some weird results. It seems the FormulaRecord case is not recognising
>> string formulas.
>>
>
> Unless you have very specific needs, I'd suggest you try the hssf
usermodel
> instead. XLS2CSVmra opperates at a very low level, on the records, and is
> exposed to lots of excel oddities. The hssf usermodel hides that sort of
> thing from you
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



      

Reply via email to