将文档保存为网页Saving Documents as Web Pages
06/08/2017
本文内容
在 Microsoft Excel 中,可以将工作簿、工作表、图表、区域、查询表、数据透视表、打印区域或自动筛选区域保存到网页中。In Microsoft Excel, you can save a workbook, worksheet, chart, range, query table, PivotTable report, print area, or AutoFilter range to a Web page. 也可以直接在 Excel 中编辑 HTML 文件。You can also edit HTML files directly in Excel.
将文档保存为网页Saving a Document as a Web Page
将文档保存为网页是一个创建并保存 HTML 文件及所有支持文件的过程。Saving a document as a Web page is the process of creating and saving an HTML file and any supporting files. 为此,请使用To do this, use the
ActiveWorkbook.SaveAs _
Filename:="C:\Reports\myfile.htm", _
FileFormat:=xlHTML
自定义网页Customizing the Web Page
您可以通过设置You can customize the appearance, content, browser support, editing support, graphics formats, screen resolution, file organization, and encoding of the HTML document by setting properties of the DefaultWebOptions 对象包含应用程序级的属性。The DefaultWebOptions object contains application-level properties. 任何具有相同名称的工作簿级属性设置(包含在 WebOptions 对象中)都优先于这些设置。These settings are overridden by any workbook-level property settings that have the same names (these are contained in the WebOptions object).
设置属性后,可以使用After setting the attributes, you can use the 以下示例设置各种应用程序级属性,然后设置活动工作簿的The following example sets various application-level properties and then sets the 最后,示例将区域保存为“C:\Reports\1998_Q1.htm”。Finally, the example saves the range as "C:\Reports\1998_Q1.htm."
With Application.DefaultWebOptions
.RelyonVML = True
.AllowPNG = True
.PixelsPerInch = 96
End With
With ActiveWorkbook
.WebOptions.AllowPNG = False
With .PublishObjects(1)
.FileName = "C:\Reports\1998_Q1.htm"
.Publish
End With
End With
还可以将文件直接保存到 Web 服务器。You can also save the files directly to a Web server. The following example saves a range to a Web server, giving the Web page the URL address https://example.homepage.com/annualreport.htm.
With ActiveWorkbook
With .WebOptions
.RelyonVML = True
.PixelsPerInch = 96
End With
With .PublishObjects(1)
.FileName = _
"https://example.homepage.com/annualreport.htm"
.Publish
End With
End With
在文档中打开 HTML Microsoft ExcelOpening an HTML Document in Microsoft Excel
若要在文档中编辑 HTML Excel,请首先使用 Open 方法To edit an HTML document in Excel, first open the document by using the 下面的示例打开文件"C:\Reports\1997_Q4.htm"进行编辑。The following example opens the file "C:\Reports\1997_Q4.htm" for editing.
Workbooks.Open Filename:="C:\Reports\1997_Q4.htm"
打开文件后,可以通过设置 DefaultWebOptions 和 WebOptions 对象的属性来自定义 HTML 文档的外观、内容、浏览器支持、编辑支持、图形格式、屏幕分辨率、文件组织和编码。After opening the file, you can customize the appearance, content, browser support, editing support, graphics formats, screen resolution, file organization, and encoding of the HTML document by setting properties of the DefaultWebOptions and WebOptions objects.
支持和反馈Support and feedback
有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.