aspose.excel转html,c# - Aspose converting Excel to HTML - htmlAgilePack - Stack Overflow

该博客讨论了如何将Excel文件转换为HTML,并在预览时确保生成的HTML文件宽度与弹出窗口完全匹配,避免水平滚动。通过使用Aspose库进行转换并设置特定的保存选项,目标是实现只允许垂直滚动的页面布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am trying to convert an Excel file to an HTML file which I later display on the page as a preview. Everything works well except one element. I display the HTML file in the pop-up window and it does not fit in completely. How to make the generated HTML file match the width of the window? My point is that I do not have to scroll the page horizontally (only vertically like a classic scroll).

private void ConvertExcelToHtml(Stream stream, string fileName, string directory, string virtualDirectory, bool force)

{

var htmlPath = Path.Combine(directory, $"{fileName}.html");

if (force == false && System.IO.File.Exists(htmlPath))

{

return;

}

log.DebugFormat("Converting Excel=>HTML: '{0}'", fileName);

var document = new Workbook(stream);

this.RemoveHeader(document);

var htmlSaveOptions = new Aspose.Cells.HtmlSaveOptions(SaveFormat.Html)

{

HiddenColDisplayType = HtmlHiddenColDisplayType.Remove,

HiddenRowDisplayType = HtmlHiddenRowDisplayType.Remove,

AttachedFilesDirectory = directory,

ExportActiveWorksheetOnly = true,

};

htmlSaveOptions.ImageOptions.ImageFormat = ImageFormat.Png;

document.Save(htmlPath, htmlSaveOptions);

var htmlDoc = new HtmlDocument();

htmlDoc.Load(htmlPath);

htmlDoc.Save(htmlPath);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值