Hi Dominik,

I try your code,but when I run it,it also arise NullPointerExceptions at 
following code:

>System.out.println("Font at index: " + i + ": " + rich.getFontAtIndex(i))

Does anyone  know how to solve above error?
Thanks.


----- Original Message ----- 
From: "Dominik Stadler" <[email protected]>
To: "POI Users List" <[email protected]>
Sent: Thursday, October 31, 2013 3:11 AM
Subject: Re: question about read excel file


> Hi,
> 
> It seems you should be able to read the RichText-information via the "runs"
> by casting to XSSFRichTextString, however when I create such a XLSX in
> LibreOffice, POI actually produces NullPointerExceptions because some data
> is not filled as POI expects, does it work on your file?
> 
>        XSSFRichTextString rich = (XSSFRichTextString)
> row.getCell(0).getRichStringCellValue();
> 
>        for(int i = 0;i < rich.length();i++) {
>            System.out.println("Font at index: " + i + ": " +
> rich.getFontAtIndex(i));
>        }
> 
>        System.out.println("Runs: " + rich.numFormattingRuns());
>        for(int i = 0;i < rich.numFormattingRuns();i++) {
>            System.out.println("Index-" + i + ": " +
> rich.getIndexOfFormattingRun(i));
>            System.out.println("Font-" + i + ": " +
> rich.getFontOfFormattingRun(i));
>        }
> 
> Dominik.
> 
> 
> On Wed, Oct 30, 2013 at 4:22 AM, Edward King <[email protected]> wrote:
> 
>> I use poi to read the content of an excel file,the excel file is follows:
>> This is a test!           //I set the font and color,such as 'is' is green
>> and 'test' is red color
>>
>> My java code is follows:
>>
>>   InputStream inp = new FileInputStream("demo.xlsx");
>>   Workbook wb = WorkbookFactory.create(inp);
>>   Sheet sheet = wb.getSheetAt(0);
>>   org.apache.poi.ss.usermodel.Row row = sheet.getRow(0);
>>   row = sheet.getRow(0);
>>   title=row.getCell(0).getRichStringCellValue().getString();
>>   System.out.println(title);
>>
>> When I run above code,I only get the plain text "This is a test!" ,the
>> font and color is missing,how can I get the text with font and color?
>>
>> Thanks!
>>
>>
>>
>> ---------------------------------------------------------------------------------------------------
>> Confidentiality Notice: The information contained in this e-mail and any
>> accompanying attachment(s)
>> is intended only for the use of the intended recipient and may be
>> confidential and/or privileged of
>> Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader
>> of this communication is
>> not the intended recipient, unauthorized use, forwarding, printing,
>>  storing, disclosure or copying
>> is strictly prohibited, and may be unlawful.If you have received this
>> communication in error,please
>> immediately notify the sender by return e-mail, and delete the original
>> message and all copies from
>> your system. Thank you.
>>
>> ---------------------------------------------------------------------------------------------------
>>
>
---------------------------------------------------------------------------------------------------
Confidentiality Notice: The information contained in this e-mail and any 
accompanying attachment(s) 
is intended only for the use of the intended recipient and may be confidential 
and/or privileged of 
Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of 
this communication is 
not the intended recipient, unauthorized use, forwarding, printing,  storing, 
disclosure or copying 
is strictly prohibited, and may be unlawful.If you have received this 
communication in error,please 
immediately notify the sender by return e-mail, and delete the original message 
and all copies from 
your system. Thank you. 
---------------------------------------------------------------------------------------------------

Reply via email to