0
我得到一個字符串包含HTML內容,如: 「如何顯示HTML樣式的文本在Excel單元格中使用的SpreadsheetGear
我是頭
你好
」 現在,我希望寫這個字符串轉換爲Excel單元格,並讓這些html標籤可以展示他們的風格。
我怎麼能做到這一點跟的SpreadsheetGear?
我得到一個字符串包含HTML內容,如: 「如何顯示HTML樣式的文本在Excel單元格中使用的SpreadsheetGear
你好
」 現在,我希望寫這個字符串轉換爲Excel單元格,並讓這些html標籤可以展示他們的風格。
我怎麼能做到這一點跟的SpreadsheetGear?
的SpreadsheetGear不支持解析和渲染HTML。如果您將這種類型的內容放入單元格中,則會顯示原始標記。
的SpreadsheetGear不支持添加富文本(RTF)的細胞,但你需要使用的SpreadsheetGear API使用要做到這一點:
下面的例子將呈現類似這樣:
// Create new workbook.
IWorkbook workbook = Factory.GetWorkbook();
IWorksheet worksheet = workbook.ActiveWorksheet;
IRange cells = worksheet.Cells;
// Add text to A1 which we'll format below...
cells["A1"].Value = "This Is My Header\n\nHello World!";
// Format "header" as bold and with a larger font size.
ICharacters charsHeader = cells["A1"].GetCharacters(0, 17);
charsHeader.Font.Bold = true;
charsHeader.Font.Size = 18;
// Format "Hello" text.
ICharacters charsHello = cells["A1"].GetCharacters(19, 5);
charsHello.Font.Italic = true;
charsHello.Font.Color = SpreadsheetGear.Colors.DarkRed;
// Format "World" text.
ICharacters charsWorld = cells["A1"].GetCharacters(25, 5);
charsWorld.Font.Underline = UnderlineStyle.Single;
charsWorld.Font.Color = SpreadsheetGear.Colors.DarkBlue;
// Expand column width to accommodate header text
cells["A:A"].ColumnWidth = 30;
// Save and view in Excel...
workbook.SaveAs(@"c:\temp\rtf.xlsx", FileFormat.OpenXMLWorkbook);
// ...or attach to SpreadsheetGear's WPF WorkbookView to
// confirm RTF is displaying as expected (NOTE: the WinForms
// WorkbookView does not support rendering RTF).
workbookView.ActiveWorkbook = workbook;