You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Guilherme Mussi <gm...@gmail.com> on 2010/05/21 15:23:50 UTC

Problem using newline in XSSFRichTextString (a bug, perhaps?)

Hello All,
I am making a tool to translate html to a XSSFRichTextString

When i find a br tag, i'm simply appending a \n character, like this:

richTextString.append("\n", font);

Unfortunately, if i do this, the .xslx file gets damaged and doesn't open
correctly (excel always offers to repair it)

if, nevertheless, i do this:

richTextString.append("a\na", font);

(some character before and after the \n)

everything works fine.

I can't get through this problem.

Perhaps comeone here can help me?


--
Guilherme Petterle Silveira Mussi

Conrad Caine Media Applications GmbH

Mobile: +55 53 91257012
Office: +55 53 30275721

"Any fool can know. The point is to understand." - Albert Einstein

Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 21 May 2010, Guilherme Mussi wrote:
> visually, excel represents my file without the newlines.

To check - does excel not show the newlines in excel, or do you mean it 
shows them but you can't spot them in the xml?

> excel saves its own newlines like this:
> <t xml:space="*preserve*">text before the newline</t>

So it adds the space="preserve" flag? But where is the newline itself?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Guilherme Mussi <gm...@gmail.com>.
I didn't quite understand your question..
visually, excel represents my file without the newlines.

excel saves its own newlines like this:
<t xml:space="*preserve*">text before the newline</t>

could you undertand ?
--
Guilherme Petterle Silveira Mussi

Conrad Caine Media Applications GmbH

Mobile: +55 53 91257012
Office: +55 53 30275721

"Any fool can know. The point is to understand." - Albert Einstein


On Fri, May 21, 2010 at 1:00 PM, Nick Burch <ni...@alfresco.com> wrote:

> On Fri, 21 May 2010, Guilherme Mussi wrote:
>
>> just to make it clear: the problem is with excel itself
>>
>> when i append just a "\n" in the XSSFRichTextString, it creates a node
>> with
>> just a newline character.
>> The problem is excel simply ignore this node (it pops up a warning message
>> saying the file is damaged)
>>
>
> How does excel represent the same newline though?
>
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 21 May 2010, Guilherme Mussi wrote:
> just to make it clear: the problem is with excel itself
>
> when i append just a "\n" in the XSSFRichTextString, it creates a node with
> just a newline character.
> The problem is excel simply ignore this node (it pops up a warning message
> saying the file is damaged)

How does excel represent the same newline though?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Guilherme Mussi <gm...@gmail.com>.
Hi Nick
just to make it clear: the problem is with excel itself

when i append just a "\n" in the XSSFRichTextString, it creates a node with
just a newline character.
The problem is excel simply ignore this node (it pops up a warning message
saying the file is damaged)

--
Guilherme Petterle Silveira Mussi

Conrad Caine Media Applications GmbH

Mobile: +55 53 91257012
Office: +55 53 30275721

"Any fool can know. The point is to understand." - Albert Einstein


On Fri, May 21, 2010 at 11:53 AM, Nick Burch <ni...@alfresco.com>wrote:

> On Fri, 21 May 2010, Guilherme Mussi wrote:
>
>> the xml generated by poi with
>>
>
> I think something (your editor? email client?) has munged the xml. Any
> chance you could re-post it having double checked that you have the real
> thing? <#> and - are both a sign of something having gone wrong...
>
> (At the moment, I can't easily spot what's different)
>
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 21 May 2010, Guilherme Mussi wrote:
> the xml generated by poi with

I think something (your editor? email client?) has munged the xml. Any 
chance you could re-post it having double checked that you have the real 
thing? <#> and - are both a sign of something having gone wrong...

(At the moment, I can't easily spot what's different)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Guilherme Mussi <gm...@gmail.com>.
Sorry for 3 messages in a row, but i made a mistake in the previous email

the fact is poi acts correctly.

it puts there a tag like
<t>
</t>

(the newline is there)

but excel cannot interpret it when there is no printable character there.
i guess the solution there would be to use that xml:space="*preserve*" in
this tag
--
Guilherme Petterle Silveira Mussi

Conrad Caine Media Applications GmbH

Mobile: +55 53 91257012
Office: +55 53 30275721

"Any fool can know. The point is to understand." - Albert Einstein


On Fri, May 21, 2010 at 11:46 AM, Guilherme Mussi <gm...@gmail.com> wrote:

> Complementing:
> The problem is when i use this command:
>
> richTextString.append("\n", font);
>
> in the sharedStrings.xml i will find this:
>
> <t />
>
> which excel doesn't know how to interpret
> any ideas to where i can fix this?
>
>
>
> --
> Guilherme Petterle Silveira Mussi
>
> Conrad Caine Media Applications GmbH
>
> Mobile: +55 53 91257012
> Office: +55 53 30275721
>
> "Any fool can know. The point is to understand." - Albert Einstein
>
>
> On Fri, May 21, 2010 at 11:40 AM, Guilherme Mussi <gm...@gmail.com>wrote:
>
>> Hi nick,
>>
>> the xml generated by poi with
>>
>> richTextString.append("my word", font);
>> richTextString.append(".\n-", font);
>> richTextString.append("new line", font);
>>
>> is:
>>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <r>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <rPr>
>>    <i val="*true*" />
>>    <sz val="*12.0*" />
>>    <rFont val="*Calibri*" />
>>   </rPr>
>>    <t>my word</t>
>>    </r>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <r>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <rPr>
>>    <i val="*true*" />
>>    <sz val="*12.0*" />
>>    <rFont val="*Calibri*" />
>>   </rPr>
>>    <t>. -</t>
>>    </r>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <r>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <rPr>
>>    <i val="*true*" />
>>    <sz val="*12.0*" />
>>    <rFont val="*Calibri*" />
>>   </rPr>
>>    <t>new line</t>
>>    </r>
>>
>> the xml generated by excel
>>
>> - <#128bb54801f73974_128bb4f4d3196134_> <r>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <rPr>
>>    <i val="*true*" />
>>    <sz val="*12.0*" />
>>    <rFont val="*Calibri*" />
>>   </rPr>
>>      <t xml:space="*preserve*">my word</t>
>>    </r>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <r>
>>  - <#128bb54801f73974_128bb4f4d3196134_> <rPr>
>>    <i val="*true*" />
>>    <sz val="*12.0*" />
>>    <rFont val="*Calibri*" />
>>   </rPr>
>>    <t>new line</t>
>>    </r>
>>
>> do you know what i can do with this? is it possible to fix it somehow?
>>
>> Regards,
>>
>>
>>
>> --
>> Guilherme Petterle Silveira Mussi
>>
>> Conrad Caine Media Applications GmbH
>>
>> Mobile: +55 53 91257012
>> Office: +55 53 30275721
>>
>> "Any fool can know. The point is to understand." - Albert Einstein
>>
>>
>> On Fri, May 21, 2010 at 10:34 AM, Nick Burch <ni...@alfresco.com>wrote:
>>
>>> On Fri, 21 May 2010, Guilherme Mussi wrote:
>>>
>>>> I am making a tool to translate html to a XSSFRichTextString
>>>>
>>>> When i find a br tag, i'm simply appending a \n character, like this:
>>>>
>>>> richTextString.append("\n", font);
>>>>
>>>> Unfortunately, if i do this, the .xslx file gets damaged and doesn't
>>>> open
>>>> correctly (excel always offers to repair it)
>>>>
>>>
>>> I'd suggest you try creating the same file in excel. Then, unzip the
>>> .xlsx file (it's basically a zip file of xml files), and look at the shared
>>> strings table (where most cell string contents go). See what excel did there
>>> instead, then try doing the same
>>>
>>> Nick
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>>
>>
>

Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Guilherme Mussi <gm...@gmail.com>.
Complementing:
The problem is when i use this command:

richTextString.append("\n", font);

in the sharedStrings.xml i will find this:

<t />

which excel doesn't know how to interpret
any ideas to where i can fix this?


--
Guilherme Petterle Silveira Mussi

Conrad Caine Media Applications GmbH

Mobile: +55 53 91257012
Office: +55 53 30275721

"Any fool can know. The point is to understand." - Albert Einstein


On Fri, May 21, 2010 at 11:40 AM, Guilherme Mussi <gm...@gmail.com> wrote:

> Hi nick,
>
> the xml generated by poi with
>
> richTextString.append("my word", font);
> richTextString.append(".\n-", font);
> richTextString.append("new line", font);
>
> is:
>
>  - <#128bb4f4d3196134_> <r>
>  - <#128bb4f4d3196134_> <rPr>
>    <i val="*true*" />
>    <sz val="*12.0*" />
>    <rFont val="*Calibri*" />
>   </rPr>
>    <t>my word</t>
>    </r>
>  - <#128bb4f4d3196134_> <r>
>  - <#128bb4f4d3196134_> <rPr>
>    <i val="*true*" />
>    <sz val="*12.0*" />
>    <rFont val="*Calibri*" />
>   </rPr>
>    <t>. -</t>
>    </r>
>  - <#128bb4f4d3196134_> <r>
>  - <#128bb4f4d3196134_> <rPr>
>    <i val="*true*" />
>    <sz val="*12.0*" />
>    <rFont val="*Calibri*" />
>   </rPr>
>    <t>new line</t>
>    </r>
>
> the xml generated by excel
>
> - <#128bb4f4d3196134_> <r>
>  - <#128bb4f4d3196134_> <rPr>
>    <i val="*true*" />
>    <sz val="*12.0*" />
>    <rFont val="*Calibri*" />
>   </rPr>
>      <t xml:space="*preserve*">my word</t>
>    </r>
>  - <#128bb4f4d3196134_> <r>
>  - <#128bb4f4d3196134_> <rPr>
>    <i val="*true*" />
>    <sz val="*12.0*" />
>    <rFont val="*Calibri*" />
>   </rPr>
>    <t>new line</t>
>    </r>
>
> do you know what i can do with this? is it possible to fix it somehow?
>
> Regards,
>
>
>
> --
> Guilherme Petterle Silveira Mussi
>
> Conrad Caine Media Applications GmbH
>
> Mobile: +55 53 91257012
> Office: +55 53 30275721
>
> "Any fool can know. The point is to understand." - Albert Einstein
>
>
> On Fri, May 21, 2010 at 10:34 AM, Nick Burch <ni...@alfresco.com>wrote:
>
>> On Fri, 21 May 2010, Guilherme Mussi wrote:
>>
>>> I am making a tool to translate html to a XSSFRichTextString
>>>
>>> When i find a br tag, i'm simply appending a \n character, like this:
>>>
>>> richTextString.append("\n", font);
>>>
>>> Unfortunately, if i do this, the .xslx file gets damaged and doesn't open
>>> correctly (excel always offers to repair it)
>>>
>>
>> I'd suggest you try creating the same file in excel. Then, unzip the .xlsx
>> file (it's basically a zip file of xml files), and look at the shared
>> strings table (where most cell string contents go). See what excel did there
>> instead, then try doing the same
>>
>> Nick
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>

Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Guilherme Mussi <gm...@gmail.com>.
Hi nick,

the xml generated by poi with

richTextString.append("my word", font);
richTextString.append(".\n-", font);
richTextString.append("new line", font);

is:

 - <#> <r>
 - <#> <rPr>
   <i val="*true*" />
   <sz val="*12.0*" />
   <rFont val="*Calibri*" />
  </rPr>
   <t>my word</t>
   </r>
 - <#> <r>
 - <#> <rPr>
   <i val="*true*" />
   <sz val="*12.0*" />
   <rFont val="*Calibri*" />
  </rPr>
   <t>. -</t>
   </r>
 - <#> <r>
 - <#> <rPr>
   <i val="*true*" />
   <sz val="*12.0*" />
   <rFont val="*Calibri*" />
  </rPr>
   <t>new line</t>
   </r>

the xml generated by excel

- <#> <r>
 - <#> <rPr>
   <i val="*true*" />
   <sz val="*12.0*" />
   <rFont val="*Calibri*" />
  </rPr>
     <t xml:space="*preserve*">my word</t>
   </r>
 - <#> <r>
 - <#> <rPr>
   <i val="*true*" />
   <sz val="*12.0*" />
   <rFont val="*Calibri*" />
  </rPr>
   <t>new line</t>
   </r>

do you know what i can do with this? is it possible to fix it somehow?

Regards,


--
Guilherme Petterle Silveira Mussi

Conrad Caine Media Applications GmbH

Mobile: +55 53 91257012
Office: +55 53 30275721

"Any fool can know. The point is to understand." - Albert Einstein


On Fri, May 21, 2010 at 10:34 AM, Nick Burch <ni...@alfresco.com>wrote:

> On Fri, 21 May 2010, Guilherme Mussi wrote:
>
>> I am making a tool to translate html to a XSSFRichTextString
>>
>> When i find a br tag, i'm simply appending a \n character, like this:
>>
>> richTextString.append("\n", font);
>>
>> Unfortunately, if i do this, the .xslx file gets damaged and doesn't open
>> correctly (excel always offers to repair it)
>>
>
> I'd suggest you try creating the same file in excel. Then, unzip the .xlsx
> file (it's basically a zip file of xml files), and look at the shared
> strings table (where most cell string contents go). See what excel did there
> instead, then try doing the same
>
> Nick
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: Problem using newline in XSSFRichTextString (a bug, perhaps?)

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 21 May 2010, Guilherme Mussi wrote:
> I am making a tool to translate html to a XSSFRichTextString
>
> When i find a br tag, i'm simply appending a \n character, like this:
>
> richTextString.append("\n", font);
>
> Unfortunately, if i do this, the .xslx file gets damaged and doesn't open
> correctly (excel always offers to repair it)

I'd suggest you try creating the same file in excel. Then, unzip the .xlsx 
file (it's basically a zip file of xml files), and look at the shared 
strings table (where most cell string contents go). See what excel did 
there instead, then try doing the same

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org