HTMLをエクセルブックオブジェクトにロードする際にDIVタグのレイアウトをサポート
Contents
[
Hide
]
通常、divタグのレイアウトはExcelブックオブジェクトにHTMLをロードする際に無視されます。ただし、divタグのレイアウトが無視されないようにしたい場合は、HTMLLoadOptions.SupportDivTagプロパティをtrueに設定してください。このプロパティの既定値はfalseです。
次のサンプルコードは、HTMLLoadOptions.SupportDivTag プロパティの使用法を示しています。入力HTML内で使用されたAsposeロゴ(5115218.png)およびコードによって生成された出力エクセルファイル(5115220.xlsx)をダウンロードしてください。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
var export_html = @" | |
<html> | |
<body> | |
<table> | |
<tr> | |
<td> | |
<div>This is some Text.</div> | |
<div> | |
<div> | |
<span>This is some more Text</span> | |
</div> | |
<div> | |
<span>abc@abc.com</span> | |
</div> | |
<div> | |
<span>1234567890</span> | |
</div> | |
<div> | |
<span>ABC DEF</span> | |
</div> | |
</div> | |
<div>Generated On May 30, 2016 02:33 PM <br />Time Call Received from Jan 01, 2016 to May 30, 2016</div> | |
</td> | |
<td>"; | |
export_html = export_html + " <img src=" + dataDir + "ASpose_logo_100x100.png" + @" /> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</html>"; | |
using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(export_html))) | |
{ | |
// Specify HTML load options, support div tag layouts | |
HtmlLoadOptions loadOptions = new HtmlLoadOptions(LoadFormat.Html); | |
loadOptions.SupportDivTag = true; | |
// Create workbook object from the html using load options | |
Workbook wb = new Workbook(ms, loadOptions); | |
// Auto fit rows and columns of first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
ws.AutoFitRows(); | |
ws.AutoFitColumns(); | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "DivTagsLayout_out.xlsx", Aspose.Cells.SaveFormat.Xlsx); | |
} |