Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Fri Nov 07, 2014 10:46 am

Could I simply write html to a cell instead of a rich text?
for example I want to use this: "<span style=\"border-width:thin;border-color:#FFFFFF;\"><font color=#000000 size=8><b>U = Unchanged rate</b></font></span>"

ali.baghdadi
 
Posts: 4
Joined: Tue Oct 28, 2014 7:30 am

Mon Nov 10, 2014 2:05 am

Dear ali.baghdadi,

Thanks for your inquiry.

For your requirement, please refer to the code below:
Code: Select all
Workbook workbook = new Workbook();
Document doc = new Document();

StringReader sr = new StringReader("<span style=\"border-width:thin;border-color:#FFFFFF;\"><font color=#000000 size=8><b>U = Unchanged rate</b></font></span>");
doc.LoadHTML(sr, XHTMLValidationType.None);
int index = 0;

foreach (Section section in doc.Sections)
{
    foreach (Paragraph paragraph in section.Paragraphs)
    {
        if (paragraph.Items.Count > 0)
        {
            workbook.Worksheets[0].Range["A4"].RichText.Text += paragraph.Text;
            foreach (var item in paragraph.Items)
            {
                if (item is Spire.Doc.Fields.TextRange)
                {
                    for (int i = index; i < (item as Spire.Doc.Fields.TextRange).Text.Length + index; i++)
                    {
                        Font font = (item as Spire.Doc.Fields.TextRange).CharacterFormat.Font;
                        ExcelFont excelFont = workbook.CreateFont(font);
                        excelFont.Color = (item as Spire.Doc.Fields.TextRange).CharacterFormat.TextColor;
                        workbook.Worksheets[0].Range["A4"].RichText.SetFont(i, i, excelFont);
                    }
                }
                index += (item as Spire.Doc.Fields.TextRange).Text.Length;
            }
        }
    }
}
workbook.Worksheets[0].Range["A4"].AutoFitRows();
workbook.SaveToFile("3846.xlsx", ExcelVersion.Version2010);


Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Wed Nov 12, 2014 8:28 am

Dear ali.baghdadi,

Have you tried the code snippet I provided? Has the problem been resolved?
Please give us some feedback if convenience.

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Return to Spire.XLS