TextBox.setHtmlText question

Hi,

I’m using setHtmlText to insert an HTML formatted text into a TextBox.
I encoutered an issue I manage to bypass : multiple space char (" ") should be intepreted as one space.

Now a question : After balise, font size provided by Java code source (textbox.getFont().setSize(14):wink: seems to be overwritten by another value I didn’t manage to determine.

Is there any way to control this font size ? (size is the same for all the document)

thanks you

Hi,


Please paste your sample code and attach your template files to reproduce the issue on our end. Also, which version of the product your are using?

Thank you.

Here is code source :
int textboxIndex = sheet.getTextBoxes().add(cellComment.getRow(), cellComment.getColumn(), (int)height, (int)width);
TextBox textbox0 = sheet.getTextBoxes().get(textboxIndex);
textbox0.setHtmlText(str.toString());
textbox0.getFont().setSize(14);
textbox0.setLocked(true);

str is a Stringbuffer build by parsing attached HTML file (rename into .txt)
and the result is the jpg one

Edit : .Cells v7.0.0.3 - JDK 1.4

Hi,

Please see the code below, it will remove all the double spaces. I have also attached the output xlsx and screenshot.

Java


String path = “F:\Shak-Data-RW\Downloads\Output.xlsx”;


String str = " <p style=“margin-top: 0px”> Dear all, <p style=“margin-top: 0px”> <p style=“margin-top: 0px”> As communicated to you in June, the roll-out of SAFIR v3.0 will take place between the end of September and early October. <p style=“margin-top: 0px”> <p style=“margin-top: 0px”> On top of adding com<font color="#ff0000">mitments and enabling the user to generate for each deal the full quarterly review, will incorporate additional credit related information. Most notably, the detailed cash fl<font color="#000000">ow will now be displayed in order to show Free Cash Flow Before Debt Service - with customized details deal b “;


//This code will remove all double spaces

while(str.indexOf(” “)>0)

{

System.out.println(str);

str = str.replaceAll(” ", " “);


int idx = str.indexOf(” ");

System.out.println(idx);

}


Workbook workbook = new Workbook();


Worksheet sheet = workbook.getWorksheets().get(0);


int textboxIndex = sheet.getTextBoxes().add(5, 5, 300, 300);

TextBox textbox0 = sheet.getTextBoxes().get(textboxIndex);

textbox0.setHtmlText(str.toString());

textbox0.getFont().setSize(14);

textbox0.setLocked(true);



workbook.save(path);

Screenshot:

Hi,


I am using v7.0.1.2, I think it works fine. Following is my sample code and please find attached the output file.

Sample code:
Workbook wb = new Workbook();
Worksheet sheet = wb.getWorksheets().get(0);

int textboxIndex = sheet.getTextBoxes().add(2, 1, 500, 500);
TextBox textbox0 = sheet.getTextBoxes().get(textboxIndex);

StringBuffer fileData = new StringBuffer(10000);
BufferedReader reader = new BufferedReader(
new FileReader(“str.txt”)); //I saved the contents in your attached txt file to “str.txt”
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
buf = new char[1024];
}
reader.close();

textbox0.setHtmlText(fileData.toString());
textbox0.getFont().setSize(14);
textbox0.setLocked(true);

wb.save(“outtextbox_2.xls”);



If you still find any issue, give us screen shots (you may encircle the problem area) and complete runn-able sample code to reproduce the issue, we will check it soon.

Thank you.



Hi,
it still doesn’t works with 7.0.1.2
I attach the simpliest exemple I can do

in test.htm, only “Dear” is bold
when i put it in textbox with aspose “all” is bold too. it shouldn’t

here my code :

Workbook book = new Workbook();
Worksheet sheet = book.getWorksheets().get(0);
Cell cellComment = sheet.getCells().get(“A1”);
int textboxIndex = sheet.getTextBoxes().add(cellComment.getRow(), cellComment.getColumn(), 1000, 1000);
TextBox textbox0 = sheet.getTextBoxes().get(textboxIndex);
StringBuffer str = new StringBuffer();
BufferedReader br = new BufferedReader(new FileReader(“c:\test.htm”));
String line;

while ((line=br.readLine()) != null){
str.append(line);
}

br.close();

textbox0.getFont().setSize(14);
textbox0.setHtmlText(str.toString());
textbox0.setLocked(true);
MsoTextFrame textframe0 = textbox0.getTextFrame();
textframe0.setAutoSize(false);
book.save(“c:\out.xls”, FileFormatType.EXCEL_97_TO_2003);

Kind regards

Well, I just have done some more test

Dear all : works fine
Dear all : doesn’t work

It seems, while parsing the line, aspose search the last closing tag, even if another closing tag has been found before. But the closing tag must correspond to an opening one, for exemple :

Dear all test
“test” will not be bold, because the last closing tag do not correspond to an opening one.

It’s the only logic I have found.


Hi,

I have run your code and you are right. To illustrate, I have attached my code and the output and screenshot.

We have logged this issue. We will fix it asap and update you.

This issue has been logged as CELLSJAVA-30911.

Java


String path = “F:\Shak-Data-RW\Downloads\output.xls”;


String str = " <p style=“margin-top: 0px”> Dear all ";


Workbook book = new Workbook();

Worksheet sheet = book.getWorksheets().get(0);

Cell cellComment = sheet.getCells().get(“A1”);

int textboxIndex = sheet.getTextBoxes().add(cellComment.getRow(), cellComment.getColumn(), 1000, 1000);

TextBox textbox0 = sheet.getTextBoxes().get(textboxIndex);


textbox0.getFont().setSize(14);

textbox0.setHtmlText(str.toString());

textbox0.setLocked(true);

MsoTextFrame textframe0 = textbox0.getTextFrame();

textframe0.setAutoSize(false);

book.save(path + “.out.xls”, FileFormatType.EXCEL_97_TO_2003);

Screenshot:

Hi,


Please try the new fix: v7.0.1.5


We have fixed the issue.<o:p></o:p>


Thank you

Hi,
It’s better but still not usable for production use :
While exporting to PDF format, a space is insert at each style change.
Breakline isn’t ok.
neither Underline

Please see atchament for exemple

Workbook workbook = new Workbook(“c:\src.xls”);
workbook.save(“c:\out.pdf”, FileFormatType.PDF);

made with v7.0.1.5, JDK 1.4

Hi,


I noticed the issue regarding TextBox rendering in the PDF. I have reopened your issue “CELLSJAVA-30911” again. We will figure it out soon.

Thank you.

The issues you have found earlier (filed as 30911) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.