Bug 65800 - Bold Italic Giving space
Summary: Bold Italic Giving space
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 5.1.0-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-14 08:55 UTC by Prasenjitd
Modified: 2022-01-17 12:52 UTC (History)
0 users



Attachments
Attachment of bold italics (385.96 KB, image/jpeg)
2022-01-14 09:10 UTC, Prasenjitd
Details
Attachment of bold italics (13.79 KB, application/x-zip-compressed)
2022-01-14 10:20 UTC, Prasenjitd
Details
Attachment of bold italics (3.35 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2022-01-15 05:03 UTC, Prasenjitd
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Prasenjitd 2022-01-14 08:55:15 UTC
Hi,
I am facing error in displaying bold Italics in the Excel using Apache POI.
It is generated with space in between each letter of the bold italics word.
But one more thing in the Excle cell,after I click on any cell the  space between each letter got resolved.
this is only happening in case of Bold Italics.
Please assist.
Comment 1 PJ Fanning 2022-01-14 09:07:29 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
Comment 2 Prasenjitd 2022-01-14 09:10:51 UTC
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.
Comment 3 PJ Fanning 2022-01-14 09:22:19 UTC
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.
Comment 4 Prasenjitd 2022-01-14 10:20:06 UTC
Created attachment 38159 [details]
Attachment of bold italics

Please find the attached code.
Comment 5 PJ Fanning 2022-01-14 10:24:55 UTC
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.
Comment 6 Prasenjitd 2022-01-15 05:03:03 UTC
Created attachment 38162 [details]
Attachment of bold italics
Comment 7 Prasenjitd 2022-01-15 05:03:48 UTC
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);
}



}
Comment 8 PJ Fanning 2022-01-15 09:50:51 UTC
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
Comment 9 PJ Fanning 2022-01-15 09:54:38 UTC
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);
Comment 10 Prasenjitd 2022-01-17 06:58:27 UTC
Hi there,
We have a requirement where font change can heppen per charecter ,hence the loops has been implemented.
Comment 11 PJ Fanning 2022-01-17 08:36:12 UTC
Can you at least check if the text appears better if you don't change the font on very char?
Comment 12 Prasenjitd 2022-01-17 12:52:08 UTC
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?