Summary: | Bold Italic Giving space | ||
---|---|---|---|
Product: | POI | Reporter: | Prasenjitd <prasenjit.das2> |
Component: | POI Overall | Assignee: | POI Developers List <dev> |
Status: | RESOLVED INFORMATIONPROVIDED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | 5.1.0-FINAL | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | All | ||
Attachments: |
Attachment of bold italics
Attachment of bold italics Attachment of bold italics |
Description
Prasenjitd
2022-01-14 08:55:15 UTC
Can you provide a reproducible test case? Bugzilla is for reporting bugs and making detailed requests for feature enhancements. If you are looking for advice on how to use POI, you are better off using stackoverflow.com Created attachment 38158 [details]
Attachment of bold italics
Hi ,
Please use ckEditor like Rich text where you need to make bold and italics of a word. Now write that text in Excel using apache POI.
The issue will be reproduced.
Attaching one snap shot of the Excel geberated through POI.
You will need to provide the code that you used to get you that excel result. This issue will be closed if you do not provide Java code that demonstrates the issue. Created attachment 38159 [details]
Attachment of bold italics
Please find the attached code.
That attachment is gigantic. We are volunteers. I hope noone is going to spend their time on this. If you really want assistance. You need to provide a short segment of code that demonstrates the issue. You should be able to demo this issue with less than 20 lines of code. Created attachment 38162 [details]
Attachment of bold italics
Please find the sample code. package com.cara.download.excel.main; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class CreateWorksheet2 { private FileOutputStream fileOut; public void createWorkSheet(XSSFWorkbook wb, String content, String tabName) { StringBuilder sbFileName = new StringBuilder(); sbFileName.append("test_excel.xlsx"); String fileMacTest = sbFileName.toString(); try { this.fileOut = new FileOutputStream(fileMacTest); } catch (FileNotFoundException ex) { } Sheet sheet = wb.createSheet(tabName); // Create new sheet w/ Tab name sheet.setZoom(100); // Set sheet zoom: 100% // begin insertion of values into cells Row dataRow = sheet.createRow(0); Cell A = dataRow.createCell(0); XSSFRichTextString richText = new XSSFRichTextString(); for (int i = 0; i < content.length(); i++) { Font currentFont = wb.createFont(); currentFont.setItalic(true); // italic creates space currentFont.setUnderline(Font.U_SINGLE); if (currentFont != null) richText.append(Character.toString(content.charAt(i)), (XSSFFont) currentFont); } A.setCellValue(richText); sheet.autoSizeColumn(0); try { // Write the output to a file wb.write(fileOut); fileOut.close(); } catch (IOException ex) { } } public static void main(String[] args) { String content = "GREH"; // content to be added to excel CreateWorksheet2 createWorksheet = new CreateWorksheet2(); XSSFWorkbook wb = new XSSFWorkbook(); String tabName = "Sheet1"; createWorksheet.createWorkSheet(wb, content, tabName); } } thanks for the shorter example but this does not look like a bug report to me - I would suggest that you use stackoverflow.com instead for user advice - there is a much larger user community on stackoverflow.com creating the font inside in the loop looks bad to me - excel has a limit on the number of fonts you can add to a workbook why not doing something like this (no loop, adds whole content with one append)? XSSFRichTextString richText = new XSSFRichTextString(); Font currentFont = wb.createFont(); currentFont.setItalic(true); // italic creates space currentFont.setUnderline(Font.U_SINGLE); richText.append(content, (XSSFFont) currentFont); Hi there, We have a requirement where font change can heppen per charecter ,hence the loops has been implemented. Can you at least check if the text appears better if you don't change the font on very char? Hi there, Yes it works fine if the font do not change for each char but as per the requirement we can have different font on charecters leve. Hecne same was done .But the issue occurs only in case of bold and italic. Is that an Excel issue? |