poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MSB <markbrd...@tiscali.co.uk>
Subject Re: SHow HTML text in one of the excel cell
Date Wed, 14 Jul 2010 06:34:53 GMT

If you already have the html parsed and held in a cell of an Excel workbook
then yes, you should be able to copy it successfully. Remember though that
you will need to copy both the text AND the style.

It is the automatic creation of the style by the paste operation - along
with stripping off the html mark-up of course - that you will have to
emulate. I have not had the time to do anything extensive but my initial
testing with POI indicates that there is no obvious way to achieve what you
are after using the API without modifcation. It seems as though you will
have to create a method to parse the html for you, creating CellStyles and
stripping the text from the mark-up so that you can write that to the cell
and then apply the necessary formatting. If you do decide to follow this
route, and assuming your compaines policies allow this, I am sure there are
others here who would welcome your putting together some example code and
submitting it to the examples section of the project. Remember to clear this
with your employer though as any code you do submit will become 'public
property'.

Yours

Mark B


Me Simple wrote:
> 
> Firstly, thank you for your reply. Its very informative and helpful. 
> 
> 1) Can I just check to make sure that I am clear about what you want to
> do, you wish to enter some HTML and have Excel parse that within a cell to
> present, in this case, the phrase 'My String' rendered in bold text?
> 
> My Reply: Yes. I want the phrase "My String" to be rendered in bold.
> 
> 
> 2) MS Excel parses the html and renders the phrase as bold when we paste
> the content into a cell.
> 
> 3) Please see the modified code which i am using for writing to excel.
> 
> HSSFCellStyle headerCellStyle; 
> HSSFWorkbook workBook = null; 
> 
> HSSFFont headerFont = null;
> 
> 
> workBook = new HSSFWorkbook(); 
> 
> headerFont = workBook.createFont();
> headerFont.setFontName(headerFont.FONT_ARIAL);
> headerFont.setBoldweight(headerFont.BOLDWEIGHT_BOLD);
> 
> String value = "<html>< b>My String  </html>";
> 
> HSSFCell cell = row.createCell(0); 
> HSSFRichTextString textString = new HSSFRichTextString(value); 
> headerCellStyle = workBook.createCellStyle(); 
> headerCellStyle.setFont(headerFont); 
> headerCellStyle.setWrapText(false); 
> 
> cell.setCellStyle(headerCellStyle); 
> cell.setCellValue(textString);
> 
> 
> 4) Your suggestion to parse the html using parser and detect the
> formatting and re-create the effect using CellStyle object may work,
> however, we may have to handle lots of html tags and map to appropriate
> CellStyles. 
> 
> 5) Also, I am trying to copy the html string from a excel file and writing
> to another column to see if it renders the parsed html. Will post back the
> result in the forum once I have the result.
> 
> Thanks for your reply.
> 
> 
> 
> Me Simple wrote:
>> 
>> Hi,
>> 
>> I am using Apachi POI to create a excel file on runtime. The excel file
>> may have variable number columns (number of columns depends on run time).
>> The value for One of the column has HTML parsed html string  as shown
>> below:
>> 
>> Listing 1:
>> 
>> <html>My String</html>
>> 
>>  However, when I open the excel file, the HTML column appears as is and
>> doesn't appear parsed like this one.
>> 
>> Listing 2:
>> 
>> My String
>> 
>> Is there a way to display the html as shown in listing 2 in run time. 
>> 
>> 
>> thanks.
>> 
>> The code used for creating a the cell is shown below:
>> 
>> 
>> HSSFCellStyle headerCellStyle;
>> HSSFWorkbook workBook = null;
>> 
>> workBook = new HSSFWorkbook();
>> 
>> HSSFCell cell = row.createCell(columnIndex);
>> HSSFRichTextString textString = new HSSFRichTextString(value);
>> headerCellStyle = workBook.createCellStyle();
>> headerCellStyle.setFont(getHeaderFont());
>> headerCellStyle.setWrapText(false);
>> 
>> cell.setCellStyle(headerCellStyle);
>> cell.setCellValue("<html>My String</html>");
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/SHow-HTML-text-in-one-of-the-excel-cell-tp29144294p29158728.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Mime
View raw message