以 .et 格式结尾的文件是金山办公软件 WPS Office 中的电子表格文件,.ett 是一种模板文件格式。除了通过 WPS 软件可以创建该格式的电子表格外,也可以通过格式转换的方法来获得,本文将通过使用 Spire.XLS for Java 展示如何来实现 Excel 转为 .et 和 .ett 格式。以下是具体步骤和方法。
首先,您需要在 Java 程序中添加 Spire.Xls.jar 文件作为依赖项。您可以从 这个链接 下载 JAR 文件;如果您使用 Maven,则可以通过在 pom.xml 文件中添加以下代码导入 JAR 文件。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls</artifactId>
<version>16.9.2</version>
</dependency>
</dependencies>
使用 Spire.XLS for Java 来转换 Excel(以 .xlsx 格式为例)为 .et/.ett 格式,只需要简单三行代码即可:
import com.spire.xls.*;
public class ExcelToET{
public static void main(String[] args){
//实例化Workbook类的对象
Workbook workbook = new Workbook();
//加载Excel文档
workbook.loadFromFile("test.xlsx");
//保存为et格式
workbook.saveToFile("toET.et",FileFormat.ET);
//保存为ett格式
workbook.saveToFile("toETT.ett",FileFormat.ETT);
}
}转换结果:

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。 获取有效期 30 天的临时许可证。
Spire.Office 6.10.3已发布。本次更新带来了一些新的功能,比如:Spire.PDF支持转换 PDF 到 Doc/Docx 时设置文档属性;Spire.XLS新增了实用图表,比如瀑布图、排列图和直方图等等;Spire.Presentation支持获取超链接的目标幻灯片。此外,该版本还修复了大量已知的问题。详情请阅读以下内容。
该版本涵盖了最新版的Spire.Doc, Spire.PDF, Spire.XLS, Spire.Presentation, Spire.Email, Spire.DocViewer, Spire.PDFViewer, Spire.Spreadsheet, Spire.OfficeViewer, Spire.DataExport, Spire.Barcode。
版本信息如下:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
Spire.Pdf.Conversion.PdfToDocConverter doc = new Spire.Pdf.Conversion.PdfToDocConverter(inputFile);
doc.DocxOptions.Title = "PDFTODOCX";
doc.DocxOptions.Subject = "Set document properties.";
doc.DocxOptions.Tags = "Test Tags";
doc.DocxOptions.Categories = "PDF";
doc.DocxOptions.Commments = "This document just for testing the properties";
doc.DocxOptions.Authors = "TEST";
doc.DocxOptions.LastSavedBy = "/E-iceblue";
doc.DocxOptions.Revision = (int)7.9;
doc.DocxOptions.Version = "csharp V4.0";
doc.DocxOptions.ProgramName = "Spire.Pdf for .NET";
doc.DocxOptions.Company = "冰蓝科技";
doc.DocxOptions.Manager = "测试"
doc.SaveToDocx(outputFile);
PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.Pages.Add();
PdfPolyLineAnnotation polyline = new PdfPolyLineAnnotation(page, new PointF[] { new PointF(0, 60),
new PointF(30, 45), new PointF(60, 90), new PointF(90, 80) });
polyline.Color = Color.PaleVioletRed;
polyline.Text = "This is a polygon annotation";
polyline.Author = "E-ICEBLUE";
polyline.Subject = "polygon annotation demo";
polyline.Name = "Summer";
polyline.Border = new PdfAnnotationBorder(1f);
polyline.ModifiedDate = DateTime.Now;
page.AnnotationsWidget.Add(polyline);
pdf.SaveToFile(output);
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(inputPath);
StringBuilder builder = new StringBuilder();
//抽取表格
PdfTableExtractor extractor = new PdfTableExtractor(pdf);
PdfTable[] tableLists = null;
for (int pageIndex = 0; pageIndex < pdf.Pages.Count; pageIndex++)
{
tableLists = extractor.ExtractTable(pageIndex);
if (tableLists != null && tableLists.Length > 0)
{
foreach (PdfTable table in tableLists)
{
int row = table.GetRowCount();
int column = table.GetColumnCount();
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
string text = table.GetText(i, j);
builder.Append(text + " ");
}
builder.Append("\r\n");
}
}
}
}
File.WriteAllText(outputFile, builder.ToString());
问题修复:
新功能:
Workbook workbook = new Workbook();
workbook.LoadFromFile("waterfall_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as waterfall
officeChart.ChartType = ExcelChartType.WaterFall;
//Set data range to the chart from the worksheet
officeChart.DataRange = sheet["A2:B8"];
//Data point settings as total in chart
officeChart.Series[0].DataPoints[3].SetAsTotal = true;
officeChart.Series[0].DataPoints[6].SetAsTotal = true;
//Showing the connector lines between data points
officeChart.Series[0].Format.ShowConnectorLines = true;
//Set the chart title
officeChart.ChartTitle = "Company Profit (in USD)";
//Formatting data label and legend option
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
officeChart.Legend.Position = LegendPositionType.Right;
workbook.SaveToFile("waterfall_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Pareto_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Pareto
officeChart.ChartType = ExcelChartType.Pareto;
//Set data range in the worksheet
officeChart.DataRange = sheet["A2:B8"];
//Set category values as bin values
officeChart.PrimaryCategoryAxis.IsBinningByCategory = true;
officeChart.PrimaryCategoryAxis.OverflowBinValue = 5;
officeChart.PrimaryCategoryAxis.UnderflowBinValue = 1;
//Formatting Pareto line
officeChart.Series[0].ParetoLineFormat.LineProperties.Color = System.Drawing.Color.Blue;
//Gap width settings
officeChart.Series[0].DataFormat.Options.GapWidth = 6;
//Set the chart title
officeChart.ChartTitle = "Expenses";
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Pareto_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Histogram_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as histogram
officeChart.ChartType = ExcelChartType.Histogram;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:A15"];
//Category axis bin settings
officeChart.PrimaryCategoryAxis.BinWidth = 8;
//Gap width settings
officeChart.Series[0].DataFormat.Options.GapWidth = 6;
//Set the chart title and axis title
officeChart.ChartTitle = "Height Data";
officeChart.PrimaryValueAxis.Title = "Number of students";
officeChart.PrimaryCategoryAxis.Title = "Height";
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Histogram_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Boxandwhisker_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set the chart title
officeChart.ChartTitle = "Yearly Vehicle Sales";
//Set chart type as Box and Whisker
officeChart.ChartType = ExcelChartType.BoxAndWhisker;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:E17"];
//Box and Whisker settings on first series
var seriesA = officeChart.Series[0];
seriesA.DataFormat.ShowInnerPoints = false;
seriesA.DataFormat.ShowOutlierPoints = true;
seriesA.DataFormat.ShowMeanMarkers = true;
seriesA.DataFormat.ShowMeanLine = false;
seriesA.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.ExclusiveMedian;
//Box and Whisker settings on second series
var seriesB = officeChart.Series[1];
seriesB.DataFormat.ShowInnerPoints = false;
seriesB.DataFormat.ShowOutlierPoints = true;
seriesB.DataFormat.ShowMeanMarkers = true;
seriesB.DataFormat.ShowMeanLine = false;
seriesB.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.InclusiveMedian;
//Box and Whisker settings on third series
var seriesC = officeChart.Series[2];
seriesC.DataFormat.ShowInnerPoints = false;
seriesC.DataFormat.ShowOutlierPoints = true;
seriesC.DataFormat.ShowMeanMarkers = true;
seriesC.DataFormat.ShowMeanLine = false;
seriesC.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.ExclusiveMedian;
workbook.SaveToFile("Boxandwhisker_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("treemap_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as TreeMap
officeChart.ChartType = ExcelChartType.TreeMap;
//Set data range in the worksheet
officeChart.DataRange = sheet["A2:C11"];
//Set the chart title
officeChart.ChartTitle = "Area by countries";
//Set the Treemap label option
officeChart.Series[0].DataFormat.TreeMapLabelOption = ExcelTreeMapLabelOption.Banner;
//Formatting data labels
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
workbook.SaveToFile("treemap_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sunburst_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Sunburst
officeChart.ChartType = ExcelChartType.SunBurst;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:D16"];
//Set the chart title
officeChart.ChartTitle = "Sales by annual";
//Formatting data labels
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Sunburst_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Funnel_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Funnel
officeChart.ChartType = ExcelChartType.Funnel;
//Set data range in the worksheet
officeChart.DataRange = sheet.Range["A1:B6"];
//Set the chart title
officeChart.ChartTitle = "Funnel";
//Formatting the legend and data label option
officeChart.HasLegend = false;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
workbook.SaveToFile("Funnel_chart.xlsx");
问题修复:
问题修复:
新功能:
Presentation ppt = new Presentation();
ppt.LoadFromFile(inputFile);
IAutoShape shape = ppt.Slides[1].Shapes[0] as IAutoShape;
if (shape.Click.ActionType == HyperlinkActionType.GotoSlide)
{
ISlide targetSlide = shape.Click.TargetSlide;
Console.WriteLine("index = " + targetSlide.SlideNumber);
}
问题修复:
问题修复:
Spire.Spreadsheet 5.10.0已发布。该版本修复了查看Excel文档文本内容被剪切的问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Spreadsheet-NET.html
Spire.XLS 11.10.5已发布。本次更新主要新增了一些实用图表,比如瀑布图、排列图和直方图等等。详情请阅读以下内容。
新功能:
Workbook workbook = new Workbook();
workbook.LoadFromFile("waterfall_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as waterfall
officeChart.ChartType = ExcelChartType.WaterFall;
//Set data range to the chart from the worksheet
officeChart.DataRange = sheet["A2:B8"];
//Data point settings as total in chart
officeChart.Series[0].DataPoints[3].SetAsTotal = true;
officeChart.Series[0].DataPoints[6].SetAsTotal = true;
//Showing the connector lines between data points
officeChart.Series[0].Format.ShowConnectorLines = true;
//Set the chart title
officeChart.ChartTitle = "Company Profit (in USD)";
//Formatting data label and legend option
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
officeChart.Legend.Position = LegendPositionType.Right;
workbook.SaveToFile("waterfall_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Pareto_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Pareto
officeChart.ChartType = ExcelChartType.Pareto;
//Set data range in the worksheet
officeChart.DataRange = sheet["A2:B8"];
//Set category values as bin values
officeChart.PrimaryCategoryAxis.IsBinningByCategory = true;
officeChart.PrimaryCategoryAxis.OverflowBinValue = 5;
officeChart.PrimaryCategoryAxis.UnderflowBinValue = 1;
//Formatting Pareto line
officeChart.Series[0].ParetoLineFormat.LineProperties.Color = System.Drawing.Color.Blue;
//Gap width settings
officeChart.Series[0].DataFormat.Options.GapWidth = 6;
//Set the chart title
officeChart.ChartTitle = "Expenses";
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Pareto_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Histogram_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as histogram
officeChart.ChartType = ExcelChartType.Histogram;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:A15"];
//Category axis bin settings
officeChart.PrimaryCategoryAxis.BinWidth = 8;
//Gap width settings
officeChart.Series[0].DataFormat.Options.GapWidth = 6;
//Set the chart title and axis title
officeChart.ChartTitle = "Height Data";
officeChart.PrimaryValueAxis.Title = "Number of students";
officeChart.PrimaryCategoryAxis.Title = "Height";
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Histogram_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Boxandwhisker_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set the chart title
officeChart.ChartTitle = "Yearly Vehicle Sales";
//Set chart type as Box and Whisker
officeChart.ChartType = ExcelChartType.BoxAndWhisker;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:E17"];
//Box and Whisker settings on first series
var seriesA = officeChart.Series[0];
seriesA.DataFormat.ShowInnerPoints = false;
seriesA.DataFormat.ShowOutlierPoints = true;
seriesA.DataFormat.ShowMeanMarkers = true;
seriesA.DataFormat.ShowMeanLine = false;
seriesA.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.ExclusiveMedian;
//Box and Whisker settings on second series
var seriesB = officeChart.Series[1];
seriesB.DataFormat.ShowInnerPoints = false;
seriesB.DataFormat.ShowOutlierPoints = true;
seriesB.DataFormat.ShowMeanMarkers = true;
seriesB.DataFormat.ShowMeanLine = false;
seriesB.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.InclusiveMedian;
//Box and Whisker settings on third series
var seriesC = officeChart.Series[2];
seriesC.DataFormat.ShowInnerPoints = false;
seriesC.DataFormat.ShowOutlierPoints = true;
seriesC.DataFormat.ShowMeanMarkers = true;
seriesC.DataFormat.ShowMeanLine = false;
seriesC.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.ExclusiveMedian;
workbook.SaveToFile("Boxandwhisker_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("treemap_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as TreeMap
officeChart.ChartType = ExcelChartType.TreeMap;
//Set data range in the worksheet
officeChart.DataRange = sheet["A2:C11"];
//Set the chart title
officeChart.ChartTitle = "Area by countries";
//Set the Treemap label option
officeChart.Series[0].DataFormat.TreeMapLabelOption = ExcelTreeMapLabelOption.Banner;
//Formatting data labels
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
workbook.SaveToFile("treemap_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sunburst_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Sunburst
officeChart.ChartType = ExcelChartType.SunBurst;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:D16"];
//Set the chart title
officeChart.ChartTitle = "Sales by annual";
//Formatting data labels
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Sunburst_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Funnel_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Funnel
officeChart.ChartType = ExcelChartType.Funnel;
//Set data range in the worksheet
officeChart.DataRange = sheet.Range["A1:B6"];
//Set the chart title
officeChart.ChartTitle = "Funnel";
//Formatting the legend and data label option
officeChart.HasLegend = false;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
workbook.SaveToFile("Funnel_chart.xlsx");

在处理办公自动化任务时,将 Word 文档转换为 HTML 格式是一项常见需求。无论是为了在网页端展示文档内容,还是将文档内容同步到内容管理系统,开发者都希望转换过程既能保留原有的格式,又能灵活控制转换范围。本文将通过 Java 示例代码,结合 Spire.Doc for Java 库,演示如何将 Word 文档按全文、特定节以及单个段落等不同层级转换为 HTML,帮助你根据实际业务场景选择更合适的转换方式。
在正式编写转换代码之前,我们需要引入专业的组件支持,以确保 Word 文档中的复杂元素能够被正确解析。Spire.Doc for Java 是一款功能强大的类库,它不依赖 Microsoft Office,能够让开发者在 Java 环境中快速执行创建、读取、编辑 Word 文档和格式转换等操作。
如果你使用 Maven 管理项目,只需在 pom.xml 文件中添加以下配置,即可引入该库:
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc</artifactId>
<version>14.9.5</version>
</dependency>
</dependencies>
你还可以下载 Spire.Doc for Java 安装包,解压后进行手动安装。
在完成 Spire.Doc 的安装和其他环境配置后,我们就可以利用它轻松完成 Word 到 HTML 的格式转换。
将一个 Word 文档转换为 HTML 是最常见也是最基础的操作,适用于需要将整份报告或说明书直接搬到网页上的场景。通过 Spire.Doc 提供的 Document.saveToFile() 方法,你可以直接将 Word 文本、表格及图片等元素完整导出。同时,为了保证 HTML 文件在不同环境下的展示效果,我们还可以对输出参数进行优化配置,比如设置 CSS 嵌入等。
步骤解析:
下方为完整的代码示例:
import com.spire.doc.*;
public class WordtoHtml {
public static void main(String[] args) {
// 实例化 Document 类的对象
Document doc = new Document();
// 加载 Word 文档
doc.loadFromFile("/input/示例文档.docx");
// 将 CSS 样式直接嵌入到 HTML 内部
doc.getHtmlExportOptions().setCssStyleSheetType(CssStyleSheetType.Internal);
// 将图片以 Base64 编码嵌入
//doc.getHtmlExportOptions().setImageEmbedded(true);
// 保存为 HTML 格式
doc.saveToFile("/output/ToHtml.html",FileFormat.Html);
doc.dispose();
}
}
Word 源文档和 HTML 文件对比预览:

在不需要精细控制 HTML 输出格式的情况下,可以直接调用 Document.saveToFile() 方法完成转换。Spire.Doc 默认会将文档结构与样式分离,分别输出 HTML 文件和独立的 CSS 文件。
提示:如果你还需要将 Word 文档转换为 PDF 或 TXT,也可以通过 Document.saveToFile() 方法来完成,只需将保存时指定的 FileFormat 类型替换为对应的目标格式即可。
在处理篇幅较长的技术文档时,我们可能只需要提取其中一个章节或特定的分节内容进行展示。通过获取 Word 文档中的 Section 对象,再使用 deepClone() 方法,我们可以将其添加到新的文档中,然后将其转换为 HTML。这种局部转换的方式大大提高了内容发布的灵活性,能够在不破坏原文档结构的前提下,快速生成局部的 HTML 页面。
步骤解析:
下方为完整的 Java 代码示例,展示了怎样将 Word 文档的第二节转换为 HTML 文件:
import com.spire.doc.*;
public class WordtoHtml {
public static void main(String[] args) {
// 实例化 Document 类的对象
Document doc = new Document();
// 加载 Word 文档
doc.loadFromFile("/input/示例文档.docx");
// 获取目标节
Section section = doc.getSections().get(1);
// 创建新文档并将该节克隆进去
Document newDoc = new Document();
newDoc.getSections().add(section.deepClone());
// 将 CSS 样式嵌入 HTML 头部
newDoc.getHtmlExportOptions().setCssStyleSheetType(CssStyleSheetType.Internal);
// 将图片嵌入 HTML
//newDoc.getHtmlExportOptions().setImageEmbedded(true);
// 将文件保存为 HTML 格式
newDoc.saveToFile("/output/节转换为Html.html",FileFormat.Html);
newDoc.dispose();
}
}
源文档与转换后的 HTML 对比:

如果你的需求不仅是导出为 HTML,而是需要将 Word 文档按章节或内容块拆分为多个独立文件,也可以参考按章节拆分 Word 文档的实现方式。
当需要将新闻摘要或富文本片段插入到网页中时,我们可以将指定的段落转换为 HTML。与转换节相同,由于 Spire.Doc 的转换是基于文档对象的,我们需要将选定的段落复制进一个新的文档中,然后将文档转换为 HTML 文件。这种方法能够做到准确提取出需要的片段,无需再进行二次编辑。
步骤解析:
下方的 Java 代码展示了怎样将 Word 文档中的第一节的第三段转换为 HTML 文件:
import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.interfaces.IParagraph;
public class WordtoHtml {
public static void main(String[] args) {
// 创建一个 Document 类的实例,加载 docx 文件
Document doc = new Document();
doc.loadFromFile("/input/示例文档.docx");
// 获取第一节中的第三段
Section section = doc.getSections().get(0);
Paragraph paragraph = section.getParagraphs().get(2);
// 创建新的 Document 对象,并添加一个节
Document newDoc = new Document();
Section newSection = newDoc.addSection();
// 将段落添加到新的文件中
newSection.getParagraphs().add((IParagraph) paragraph.deepClone());
// 设置 HTML 导出选项
newDoc.getHtmlExportOptions().setCssStyleSheetType(CssStyleSheetType.Internal);
// 保存 HTML 文件
newDoc.saveToFile("/output/段落转换为Html.html", FileFormat.Html);
doc.dispose();
newDoc.dispose();
}
}
源文档与转换后的 HTML 文件对比预览:

本文详细介绍了将 Word 文档转换为 HTML 的方法,不仅涵盖了转换整个 Word 文档,还深入探讨了如何利用 Spire.Doc for Java 进行精细化的节与段落转换。这种灵活的控制机制,能够帮助开发者应对各种复杂的使用场景和需求。同时,本篇指南通过设置 CSS 嵌入等方式,解决了 HTML 与 CSS 分离带来的多文件管理问题,让文档转换变得更加高效、专业。如果在使用 Spire.Doc for Java 的过程中遇到任何问题,或想了解它的更多功能,欢迎随时联系我们获取技术支持!
Spire.Presentation 6.10.2已发布。本次更新的版本支持获取超链接的目标幻灯片,此外还增强了转换Shape到图片的功能,并修复了一些已知问题。详情请阅读以下内容。
新功能:
Presentation ppt = new Presentation();
ppt.LoadFromFile(inputFile);
IAutoShape shape = ppt.Slides[1].Shapes[0] as IAutoShape;
if (shape.Click.ActionType == HyperlinkActionType.GotoSlide)
{
ISlide targetSlide = shape.Click.TargetSlide;
Console.WriteLine("index = " + targetSlide.SlideNumber);
}
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html
Spire.Doc 9.10.9已发布。本次更新增强了转换Word到PDF的功能,并且还修复了加载HTML和Word文档等时出现的问题。详情请阅读以下内容。
问题修复:
Spire.Office for Java 4.10.5已发布。本次更新带来了一些新的功能,比如:Spire.XLS for Java支持设置迷你图的标记颜色,以及转换Excel到图片时保留批注;Spire.Doc for Java支持了加载和保存.wps/.wpt格式的文档;Spire.Presentation for Java增强了转换PPT文档到图片的功能。此外还修复了其它一些已知问题,详情请阅读以下内容。
获取Spire.Office for Java 4.10.5请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
Workbook book = new Workbook();
book.loadFromFile("D:/SparkLine.xlsx");
Worksheet worksheet = book.getWorksheets().get(0);
SparklineGroupCollection sparklineGroup = worksheet.getSparklineGroups();
sparklineGroup.get(1).setMarkersColor(Color.YELLOW);
book.saveToFile("D:/result.xlsx", FileFormat.Version2016);
worksheet.getPageSetup().setPrintComments(PrintCommentType.InPlace);
Workbook workbook = new Workbook();
workbook.loadFromFile(inputFile);
workbook.saveToFile(etFile, FileFormat.ET);
workbook.saveToFile(ettFile, FileFormat.ETT);
问题修复:
新功能:
Document document = new Document();
document.loadFromFile(inputFile, FileFormat.WPS);
//document.loadFromFile(inputFile, FileFormat.WPT);
document.saveToFile(outputFile, FileFormat.WPS);
//document.saveToFile(outputFile, FileFormat.WPT);
问题修复:
问题修复:
Spire.XLS for Java 4.10.1已发布。本次更新之后成功支持支持设置迷你图的标记颜色,以及转换Excel到图片时保留批注的新功能。此外,该版本还增强了转换Excel到HTML/PDF的功能,同时还修复了添加超链接等时出现的问题。详情请阅读以下内容。
新功能:
Workbook book = new Workbook();
book.loadFromFile("D:/SparkLine.xlsx");
Worksheet worksheet = book.getWorksheets().get(0);
SparklineGroupCollection sparklineGroup = worksheet.getSparklineGroups();
sparklineGroup.get(1).setMarkersColor(Color.YELLOW);
book.saveToFile("D:/result.xlsx", FileFormat.Version2016);
worksheet.getPageSetup().setPrintComments(PrintCommentType.InPlace);
Workbook workbook = new Workbook();
workbook.loadFromFile(inputFile);
workbook.saveToFile(etFile, FileFormat.ET);
workbook.saveToFile(ettFile, FileFormat.ETT);
问题修复:
Spire.XLS 11.10.4已发布。本次更新增强了转换XLS到PDF的功能。此外,该版本还修复了加载Excel文档程序抛出异常等问题。详情请阅读以下内容。
问题修复: