Font color in textboxes

Hi there,



We often use Aspose.Cells to provide a template to our customers for their documents. They use tags for fetching desired values from database (document owner, document create date etc.). The tags work properly when they use them in the excel cells, but sometimes they use tags in textboxes with different colors or font styles.

In the attached document we have a tag “<PRN_KK>”, which is in a textbox. Aspose can replace value but it changes color to default black. Can you provide a solution for this situation? They have thousands of documents, so putting the tag in a cell is not an option.

Thank you for your help.

The codes below are for replace process, i tried to simplfy.

private static void sheetReplace(Worksheet sheet, string sReplace)
{
foreach (Aspose.Cells.Drawing.TextBox mytextbox in sheet.TextBoxes)
{
if (mytextbox.Text != null)
{
mytextbox.Text = mytextbox.Text.Replace("<PRN_KK>", sReplace);
}
}

}

Hi,

Thanks for your posting and using Aspose.Cells.

Please download and try the latest version: Aspose.Cells
for .NET v8.3.2.5
it should fix your issue.

We have tested this issue with the following sample code and it successfully replaced the textbox text without changing the text color.

I have attached the output excel file generated by the code for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\FR.KAYT.02_3+%c5%9eablon.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


Aspose.Cells.Drawing.TextBox txtBox = worksheet.TextBoxes[1];


txtBox.HtmlText = txtBox.HtmlText.Replace(“PRN_KK”, “This is test sample”);


workbook.Save(“output.xlsx”);


Actually problem solved with using HtmlText property of Aspose.Cells.Drawing.TextBox. But since HtmlText converts operators “< >” to “< >” we have to replace chars. HtmlText has value like ’ <PRN_KK> ’ .



Is there any way to get html text with operators? If not we can replace operators with their codes.

Hi,

Thanks for your posting and using Aspose.Cells.

It is actually a correct behavior, because angle brackets (< and >) have special meaning in HTML so you cannot use them as it is inside the HTML. You will have to use their code like < etc.

So please change your code like this


txtBox.HtmlText = txtBox.HtmlText.Replace("<PRN_KK>", “This is test sample”);