Hi,
For my requirement, i have to export multiple dataset to excel and create multiple sheets. Based on my data i have to create dropdown and populate the cell. For this requirement instead of direct export using excelexport dll, i have created worksheet and updated the value.
My dataset contains several html data (eg:<b><u>Test1<u> Test2</b>). If i place the data inside excell cell, it displaying with node like <b><u>Test1<u> Test2</b>, but i want to display it as formatted text as html(eg: Test1 Test2).
To reproduce this, i will paste here sample code
Infragistics.Excel.Workbook wBook = new Workbook(WorkbookFormat.Excel2007,WorkbookPaletteMode.StandardPalette);
Infragistics.Excel.
Worksheet wSheet = wBook.Worksheets.Add("Export");
wSheet.Rows[2].Cells[2].Value =
"<b><u>Test1</u> Test2</b>";
wBook.Save(@"E:\\Test.xlsx");
It is the urgent requirement for me, any solution for this issue.
Regards,
Micky
You would need to use a FormattedString instead of a normal .Net String. Once you have created a FormattedString with the raw text, set it as the Value of the cell. Then call the FormattedString.GetFont methods to get a font object for a specific range in the string and set properties on that font to format the range.
Hi Mike,
Can you please help me, how to create Formatted string for this html string "<b><u>Test 1></u><i> Test 2</i></b> Test 3 "
Thanks,
It appears you have a typo in your HTML string, so I will instead show you how to create this string:
"<b><u>Test 1</u><i> Test 2</i></b> Test 3 "
Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets.Add("Sheet1"); WorksheetCell cell = worksheet.GetCell("A1"); FormattedString fs = new FormattedString("Test 1 Test 2 Test 3 "); cell.Value = fs; // Underling "Test 1" fs.GetFont(0, 6).UnderlineStyle = FontUnderlineStyle.Single; // Italicize " Test 2" fs.GetFont(6, 7).Italic = ExcelDefaultableBoolean.True; // Bold "Test 1 Test 2" fs.GetFont(0, 13).Bold = ExcelDefaultableBoolean.True; workbook.Save("Book1.xls");
Obviously, the downside to this approach is that you need to manually convert from an HTML string to code which creates the FormattedString. But you might be able to write a utility method which takes a WorksheetCell instance and an HTML string and parses through the string to create and apply the correct formatting to the string.