
在日常的数据处理中,CSV 文件以其轻量和通用性广泛用于数据交换和系统导出。然而,它仅能提供基础的表格结构,不支持复杂排版,也不便于展示和打印。相比之下,PDF 格式则拥有固定版面、跨平台兼容和可打印的优势,非常适合用于正式报告或档案归档。
如果能将 CSV 自动转换为 PDF ,就能快速生成清晰、美观的报表,既节省手动排版时间,又能保持数据的专业呈现。本文将介绍如何使用 Spire.XLS for Java 实现这一过程——从加载 CSV 到输出高质量 PDF,仅需数行代码即可完成。
文章目录
Spire.XLS for Java 是一款功能强大的 Excel 处理类库,能够在无需安装 Microsoft Excel 的前提下,直接在 Java 程序中创建、编辑、读取和转换各种表格文件。
它支持多种格式(XLS、XLSX、CSV、ODS、HTML等),并提供丰富的格式控制功能,如字体样式、单元格边框、分页设置、打印布局等,非常适合生成 PDF 报告或表格打印文件。
安装方法
在你的 Maven 项目的 pom.xml 文件中添加以下内容,以引入Spire.XLS for Java库:
<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>15.11.3</version>
</dependency>
</dependencies>
如果你更倾向于手动安装,可以下载 Spire.XLS for Java,并将Spire.Xls.jar文件添加为项目的依赖项。
以下示例展示了如何加载 CSV 文件并将其保存为 PDF 格式:
import com.spire.xls.*;
public class CsvToPdfExample {
public static void main(String[] args) {
// 创建 Workbook 对象
Workbook workbook = new Workbook();
// 从 CSV 文件加载数据
workbook.loadFromFile("D:\\data\\input.csv", ",", 1, 1);
// 获取第一个工作表
Worksheet sheet = workbook.getWorksheets().get(0);
// 直接将工作表导出为 PDF 文件
sheet.saveToPdf("CsvToPdf.pdf");
// 释放资源
workbook.dispose();
}
}
代码解析
这种方法简单高效,非常适合处理结构相对简单的CSV文件。然而,如果某一列的内容过长,可能会被截断;而当列数较多时,表格可能会被分割到第二页,从而影响整体的阅读体验。
效果图:

你可能感兴趣:Java 将 Excel 转为 CSV 以及 CSV 转为 Excel
默认生成的 PDF通常较为简单,通过以下五个技巧,可以显著提升输出文件的清晰度和专业性。
确保文本不会被截断,同时避免单元格留白不均,从而提升整体可读性。
// 自动调整所有列宽
for (int i = 1; i <= sheet.getColumns().length; i++)
{
sheet.autoFitColumn(i);
}
// 设置默认行高
sheet.setDefaultRowHeight(18);
调整导出PDF的纸张尺寸和边距,使其更适合打印和分享。
sheet.getPageSetup().setPaperSize(PaperSizeType.PaperA4);
sheet.getPageSetup().setTopMargin(0.5);
sheet.getPageSetup().setBottomMargin(0.5);
sheet.getPageSetup().setLeftMargin(0.5);
sheet.getPageSetup().setRightMargin(0.5);
当CSV列数较多时,启用这一功能可以防止内容分页错乱,确保信息完整展示。
workbook.getConverterSetting().setSheetFitToWidth(true);
通过显示网格线,使表格结构更加清晰,特别适合用于报表展示,帮助读者更好地理解数据。
sheet.getPageSetup().isPrintGridlines(true);
统一文本的对齐方式,不仅提升了布局的整洁性,还增强了整体的可读性。
sheet.getAllocatedRange().getStyle().setHorizontalAlignment(HorizontalAlignType.Left);
sheet.getAllocatedRange().getStyle().setVerticalAlignment(VerticalAlignType.Center);
效果图:

你可能感兴趣:使用 Java 将 Excel 转为 PDF
| 问题场景 | 可能原因 | 解决方案 |
|---|---|---|
| 中文或特殊字符显示异常 | 文件编码不匹配 | 确保CSV使用UTF-8保存 |
| PDF表格分页错乱 | 页面宽度不足 | 启用SheetFitToWidth或切换横向纸张 |
| 内容被截断 | 列宽过窄 | 调用autoFitColumns()自动调整 |
| 转换性能较慢 | 文件体积较大 | 分批处理或释放资源(dispose()) |
| 样式过于单调 | 未应用格式设置 | 自定义字体、颜色、边框等样式 |
| 程序运行异常 | 文件路径错误或权限不足 | 添加文件检查与try-catch异常处理 |
| 批量转换多个文件 | 单次只处理一个文件 | 遍历文件夹批量调用转换逻辑 |
这些常见问题与技巧涵盖了从样式优化到性能提升的关键要点,能让您的转换程序更健壮、输出效果更专业。
通过本文的讲解,我们可以看到,使用 Spire.XLS for Java 将 CSV 文件转换为 PDF 报告,不仅操作简洁,而且输出效果稳定、专业。相比手动排版或依赖 Excel 软件的传统方式,这种方法能在自动化处理场景中显著提升效率。
借助 Spire.XLS 提供的灵活格式控制,开发者可以自由设置字体、边框、页边距和对齐方式,使转换后的 PDF 不仅保留数据的准确性,还具备良好的可读性与视觉美感。无论是企业报表、统计分析,还是系统自动生成文档,CSV 到 PDF 的转换都能在极短时间内完成,从而让数据展示更加清晰,信息传达更具专业性。
这种方式既满足了日常开发对自动化的需求,又兼顾了视觉呈现的品质,是构建高效文档生成系统的理想方案。
不需要。该库完全独立,可直接在任何 Java 环境中运行。
可以。Spire.XLS 生成的 PDF 保留文本信息,可进行搜索与复制。
可遍历目录下的所有 CSV 文件,循环调用 loadFromFile() 与 saveToPdf()。
支持。通过 CellRange.getStyle() 设置字体、背景色或边框样式即可。
如果您需要去除生成文档中的评估提示或解除功能限制,请联系我们获取有效期 30 天的临时许可证。
我们很高兴宣布发布Spire.Office 10.10.0。在此版本中,Spire.Doc支持从Word文件中提取页面到单独文件;Spire.XLS支持读取Office缓存云字体;Spire.Presentation支持设置音频淡入淡出时长;Spire.PDF支持验证时间戳服务URL。同时,本次更新修复了一系列已知问题。更多细节如下。
该版本涵盖了最新版的 Spire.Doc、Spire.PDF、Spire.XLS、Spire.Presentation、Spire.Barcode、Spire.Email、Spire.DocViewer、Spire.PDFViewer、Spire.OfficeViewer 和 Spire.DataExport。
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
Document doc = new Document();
doc.LoadFromFile("http://cdn.e-iceblue.cn/sample.docx");
Document extractPage = doc.ExtractPages(0, 1);
extractPage.SaveToFile("result.docx");
问题修复:
新功能:
问题修复:
新功能:
// New Append Audio
Presentation pres = new Presentation();
FileStream from_stream = File.OpenRead(inputFile);
RectangleF audioRect = new RectangleF(50, 50, 100, 100);
IAudio audio = pres.Slides[0].Shapes.AppendAudioMedia(from_stream, audioRect);
// Set the duration of the starting fade for 13s
audio.FadeInDuration = 13000f;
// Set the duration of the ending fade for 40s
audio.FadeOutDuration = 10000f;
pres.SaveToFile(outputFile, FileFormat.Pptx2013);
// Retrieve existing documents
FileStream from_stream = File.OpenRead(inputFile);
Presentation presentation = new Presentation();
presentation.LoadFromStream(from_stream, FileFormat.Auto);
foreach (IShape shape in presentation.Slides[0].Shapes)
{
if (shape is IAudio)
{
IAudio audio = shape as IAudio;
// Set the duration of the starting fade for 13s
audio.FadeInDuration = 13000f;
// Set the duration of the ending fade for 20s
audio.FadeOutDuration = 20000f;
}
}
presentation.SaveToFile(outputFile, FileFormat.Pptx2013);
// New Append Audio
Presentation pres = new Presentation();
FileStream from_stream = File.OpenRead(inputFile);
RectangleF audioRect = new RectangleF(50, 50, 100, 100);
IAudio audio = pres.Slides[0].Shapes.AppendAudioMedia(from_stream, audioRect);
// Set the start trimming time 8 seconds
audio.TrimFromStart = 8000f;
// Set the end trimming time 13 seconds
audio.TrimFromEnd = 13000f;
pres.SaveToFile(outputFile, FileFormat.Pptx2013);
// Retrieve existing documents
FileStream from_stream = File.OpenRead(inputFile);
Presentation presentation = new Presentation();
presentation.LoadFromStream(from_stream, FileFormat.Auto);
foreach (IShape shape in presentation.Slides[0].Shapes)
{
if (shape is IAudio)
{
IAudio audio = shape as IAudio;
// Set the start trimming time 8 seconds
audio.TrimFromStart = 8000f;
// Set the end trimming time 13 seconds
audio.TrimFromEnd = 13000f;
}
}
presentation.SaveToFile(outputFile, FileFormat.Pptx2013);
/table.Fill.Transparency = 0.5f; // Value range is 1-0, table default color is black
// Need to set specific table color, set color code as follows:
table[0, 0].FillFormat.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
table[0, 0].FillFormat.SolidColor.Color = Color.Orange;
调整:
Presentation ppt = new Presentation();
ppt.LoadFromFile("in.pptx");
//Add a digital signature,The parameters: string certificatePath, string certificatePassword, string comments, DateTime signTime
ppt.AddDigitalSignature("test.pfx", "e-iceblue", "111", DateTime.Now);
ppt.SaveToFile("result.pptx", Spire.Presentation.FileFormat.Pptx2016);
ppt.Dispose();
问题修复:
新功能:
TSAHttpService timestampService = new TSAHttpService("http://time2.certum.pl");
TSAResponse response = timestampService.Check();
//if it is success to receive tsa token
if (response.Success){
formatter.TimestampService = timestampService; }
问题修复:
新功能:
private void Form1_Load(object sender, EventArgs e)
{
string pdfDoc = @"test.pdf";
if (File.Exists(pdfDoc))
{
this.pdfDocumentViewer1.LoadFromFile(pdfDoc);
this.pdfDocumentViewer1.Find("FindedText", Color.Empty);
}
}
private void before_Click(object sender, EventArgs e)
{
this.pdfDocumentViewer1.FindPrevious();
}
private void next_Click(object sender, EventArgs e)
{
this.pdfDocumentViewer1.FindNext();
}
在数据处理和分析中,TXT 文件常被用作一种简单的数据存储格式,但它们缺乏结构化布局和强大的数据分析功能。与此相比,Excel 文件具有更高的可操作性,支持更丰富的数据分析、排序、过滤及图表功能。因此,将 TXT 文件转换为 Excel 格式,能够使数据更加易于管理和分析。
本文将介绍如何使用 Java 和 Spire.XLS for Java 库实现将 TXT 文件转换为 Excel 表格,帮助您更高效地处理和分析数据。
虽然 TXT 文件因其简单性而广泛使用,但它们通常不适用于复杂的数据分析和报表生成。将 TXT 文件转换为 Excel 格式有以下几大优势:
在开始之前,确保您已经安装了 Java 开发环境,并将 Spire.XLS for Java 库添加到您的项目中。以下是详细步骤。
首先,您需要安装 Java。可以从 Oracle 官方网站 下载并安装最新版本的 Java 开发工具包(JDK)。安装完成后,可以在命令行中运行 java -version 检查安装是否成功。
Spire.XLS 是一款功能强大的 Java 库,可轻松实现 Excel 文件的读取、编辑和保存。要在项目中使用 Spire.XLS,您可以下载Spire.Xls.jar,并将其手动添加到项目中。或者通过 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.xls</artifactId>
<version>15.11.3</version>
</dependency>
</dependencies>
确保您的 TXT 文件具有一致的结构,通常每一行代表一条记录,列与列之间使用某种分隔符(如逗号、制表符或空格)隔开。例如,以下是一个示例 TXT 文件:

接下来,我们将详细介绍如何使用 Java 和 Spire.XLS 将 TXT 文件转换为 Excel 格式。以下是详细实现步骤。
步骤 1:导入相关类
首先,导入 Spire.XLS for Java 库的类和其他所使用到的类:
import com.spire.xls.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
步骤 2:读取 TXT 文件
我们将使用 Java 的 BufferedReader 类来读取 TXT 文件的内容,并使用分隔符将每行拆分成列。假设 TXT 文件使用制表符(Tab)作为分隔符:
// 读取 TXT 文件
BufferedReader reader = new BufferedReader(new FileReader("数据.txt"));
String line;
List<String[]> data = new ArrayList<>();
while ((line = reader.readLine()) != null) {
// 使用制表符拆分每一行的数据
String[] row = line.split("\t");
data.add(row);
}
reader.close();
在该代码中,我们使用 split("\t") 方法按制表符分割每一行。如果您的 TXT 文件使用其他分隔符(如逗号或空格),只需修改 split() 方法中的参数。
步骤 3:创建 Excel 工作簿
接下来,我们创建一个 Excel 工作簿对象,并获取其第一个工作表:
// 创建 Excel 工作簿
Workbook workbook = new Workbook();
// 获取第一个工作表
Worksheet sheet = workbook.getWorksheets().get(0);
步骤 4:将数据写入 Excel 工作表
使用 Spire.XLS 提供的 API,将从 TXT 文件中读取的数据逐行逐列写入 Excel 工作表:
// 将数据写入工作表
for (int i = 0; i < data.size(); i++) {
String[] rowData = data.get(i);
for (int j = 0; j < rowData.length; j++) {
sheet.getCellRange(i + 1, j + 1).setValue(rowData[j]);
sheet.getCellRange(1, j + 1).getStyle().getFont().isBold(true);
}
}
注意,Excel 单元格的索引从 1 开始,因此我们在 getCellRange(i + 1, j + 1) 中加了 1 来确保正确定位单元格。
步骤 5:保存 Excel 文件
完成数据写入后,可以将工作簿保存为 Excel 文件。Spire.XLS 支持保存为 .xlsx 和 .xls 格式:
// 将工作簿保存为 Excel 文件
workbook.saveToFile("转换后的数据.xlsx", ExcelVersion.Version2016);
以下是完整的代码示例,展示了如何在 Java 中将 TXT 文件转换为 Excel 文件:
import com.spire.xls.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
public class TxtToExcel {
public static void main(String[] args) throws Exception {
// 读取 TXT 文件
BufferedReader reader = new BufferedReader(new FileReader("数据.txt"));
String line;
List<String[]> data = new ArrayList<>();
while ((line = reader.readLine()) != null) {
// 使用制表符拆分每一行的数据
String[] row = line.split("\t");
data.add(row);
}
reader.close();
// 创建 Excel 工作簿
Workbook workbook = new Workbook();
// 获取第一个工作表
Worksheet sheet = workbook.getWorksheets().get(0);
// 将数据写入工作表
for (int i = 0; i < data.size(); i++) {
String[] rowData = data.get(i);
for (int j = 0; j < rowData.length; j++) {
sheet.getCellRange(i + 1, j + 1).setValue(rowData[j]);
sheet.getCellRange(1, j + 1).getStyle().getFont().isBold(true);
}
}
// 保存为 Excel 文件
workbook.saveToFile("转换后的数据.xlsx", ExcelVersion.Version2016);
}
}
生成的Excel文档如下图所示:

在 Java 中,split() 方法可以用来根据特定的分隔符将字符串拆分成数组。假设您的 TXT 文件使用不同的分隔符,如逗号、空格或分号,您可以根据需要修改 split() 方法的参数。
例如,如果文件使用逗号分隔,您可以这样处理:
String[] row = line.split(","); // 如果使用逗号作为分隔符
在 Spire.XLS for Java 中,您可以通过访问单元格的 Style 属性来设置格式化选项,例如背景颜色、字体加粗、文本颜色等。以下是设置单元格背景颜色和字体加粗的正确 Java 写法:
// 设置单元格背景颜色为黄色
sheet.getCellRange(1, 1).getStyle().setColor(Color.YELLOW);
// 设置字体加粗
sheet.getCellRange(1, 1).getStyle().getFont().isBold(true);
在 Spire.XLS for Java 中,可以通过 AutoFitColumns() 方法来自动调整列宽以适应内容。正确的 Java 代码如下:
// 自动调整列宽
sheet.getAllocatedRange().autoFitColumns();
通过使用 Spire.XLS for Java,您可以轻松地将 TXT 文件转换为 Excel 格式,进而优化数据管理、分析和报表生成的流程。无论是日志数据、财务记录,还是大规模数据集的处理,这种方法都能够显著提升工作效率,减少人工操作。
此外,Spire.XLS 提供了强大的功能,您可以在转换过程中进一步自定义格式、处理不同的分隔符,并进行细致的数据分析和处理,帮助您充分发挥数据的价值。
如您需要去除生成文档中的评估提示或解除功能限制,请联系销售获取有效期 30 天的临时许可证。
Spire.PDFViewer 8.2.6 现已正式发布。该版本在Form、WPF和MAUI新增了“查找上一个”和“查找下一个”功能。同时,pdfDocumentViewer1.SearchText() 方法已被声明为旧方法,本版本中使用 pdfDocumentViewer1.Find() 方法替代。详情如下。
新功能:
private void Form1_Load(object sender, EventArgs e)
{
string pdfDoc = @"test.pdf";
if (File.Exists(pdfDoc))
{
this.pdfDocumentViewer1.LoadFromFile(pdfDoc);
this.pdfDocumentViewer1.Find("FindedText", Color.Empty);
}
}
private void before_Click(object sender, EventArgs e)
{
this.pdfDocumentViewer1.FindPrevious();
}
private void next_Click(object sender, EventArgs e)
{
this.pdfDocumentViewer1.FindNext();
}
Spire.Office for Java 10.10.0 已正式发布。在该版本中,Spire.Doc for Java 支持获取样式更改修订;Spire.PDF for Java支持设置 PdfTable 的列宽;Spire.Presentation for Java 支持将 Markdown 转换为 PPTX 文件。除此之外,一些在转换和操作Word、Excel、PDF和PPT文档时出现的问题也已成功被修复。更多新功能及问题修复详情如下。
https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
Document document = new Document();
document.loadFromFile(inputFile);
RevisionInfoCollection revisionInfoCollection= document.getRevisionInfos();
for (int i = 0; i < revisionInfoCollection.getCount() ; i++) {
RevisionInfo revisionInfo=revisionInfoCollection.get(i);
if(revisionInfo.getRevisionType()== RevisionType.Format_Change){
revisionInfo.accept();
//reject
revisionInfo.reject();
i--;
}
}
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
Document document = ConvertUtil.GetNewEngineDocument();
document.loadFromFile(inputFile);
RevisionInfoCollection revisionInfoCollection= document.getRevisionInfos();
for (RevisionInfo revisionInfo : (java.lang.Iterable)revisionInfoCollection) {
if(revisionInfo.getRevisionType()==RevisionType.Format_Change){
if(revisionInfo.getOwnerObject() instanceof TextRange){
TextRange range = (TextRange)revisionInfo.getOwnerObject();
TestUtil.writeAllText(outputFile,"TextRange:"+range.getText()+"\r\n");
document.setRevisionsView(RevisionsView.Original);
TestUtil.writeAllText(outputFile,"Original bold:"+range.getCharacterFormat().getBold()+"\r\n");
document.setRevisionsView(RevisionsView.Final);
TestUtil.writeAllText(outputFile,"Final bold:"+range.getCharacterFormat().getBold()+"\r\n");
}
}
}
document.close();
Document document = new Document();
document.loadFromFile("http://cdn.e-iceblue.cn/test.docx");
document.startTrackRevisions("e-iceblue");
for (int i=0; i<document.getSections().get(0).getParagraphs().get(0).getChildObjects().getCount();i++)
{
if (document.getSections().get(0).getParagraphs().get(0).getChildObjects().get(i).getDocumentObjectType()== DocumentObjectType.Text_Range)
{
TextRange tr = (TextRange) document.getSections().get(0).getParagraphs().get(0).getChildObjects().get(i);
tr.getCharacterFormat().setTextColor(Color.RED);
tr.getCharacterFormat().setFontSize(28);
tr.getCharacterFormat().setBold(true);
}
}
document.getSections().get(0).getParagraphs().get(1).appendText("aaa");
document.stopTrackRevisions();
document.saveToFile("test-out.docx");
sec.getPageSetup().setGridType(GridPitchType.Chars_And_Line);
sec.getPageSetup().setCharactersPerLine(30);
问题修复:
优化:
问题修复:
新功能:
// Create PDF document
PdfDocument doc = new PdfDocument();
// Set margins
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.setTop(unitCvtr.convertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point));
margin.setBottom(margin.getTop());
margin.setLeft(unitCvtr.convertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point));
margin.setRight(margin.getLeft());
// Add a page
PdfPageBase page = doc.getPages().add(PdfPageSize.A4, margin);
// Add table
PdfTable table = new PdfTable();
PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.black));
table.getStyle().setBorderPen(new PdfPen(brush, 0.5f));
table.getStyle().getHeaderStyle().setStringFormat(new PdfStringFormat(PdfTextAlignment.Center));
table.getStyle().setHeaderSource(PdfHeaderSource.Rows);
table.getStyle().setHeaderRowCount(1);
table.getStyle().setShowHeader(true);
table.getStyle().setCellPadding(2);
table.getStyle().setHeaderSource(PdfHeaderSource.Rows);
table.getStyle().setHeaderRowCount(1);
table.getStyle().setShowHeader(true);
// Set header font and style
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("SimSun", Font.PLAIN, 12));
table.getStyle().getHeaderStyle().setFont(font);
table.getStyle().getHeaderStyle().setBackgroundBrush(PdfBrushes.getCadetBlue());
PdfTrueTypeFont fontBody = new PdfTrueTypeFont(new Font("SimSun", Font.PLAIN, 10));
// Set even row font
table.getStyle().getDefaultStyle().setFont(fontBody);
// Set odd row font
table.getStyle().getAlternateStyle().setFont(fontBody);
// false: distribute by total width proportion, true: use set column width
table.getStyle().isFixWidth(true);
// Define data
String[] data = {"1;2;3;4;5",
"A1;B1;1,391,190,000;18.2%; ",
"A1;B1;126,490,000;1.66%; ",
"A1;B1;65,648,054;0.86%; ",
"A1;B1;82,665,600;1.08%; ",
"A1;B1;37,119,000;0.49%; ",
"A1;B1;327,216,000;4.29%; "
};
String[][] dataSource = new String[data.length][];
for (int i = 0; i < data.length; i++) {
dataSource[i] = data[i].split("[;]", -1);
}
table.setDataSource(dataSource);
for(int i = 0; i < table.getColumns().getCount(); i++)
{
PdfColumn column = table.getColumns().get(i);
column.setWidth(50);
column.setStringFormat(new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));
}
// Add table to page
table.draw(page, new Point2D.Float(0, 50));
// Save document
doc.saveToFile("addTable.pdf", FileFormat.PDF);
新功能:
Presentation pt = new Presentation();
pt.loadFromFile("input.md", FileFormat.Markdown);
pt.saveToFile("output.pptx", FileFormat.PPTX_2013);
pt.dispose();
Presentation ppt = new Presentation();
ppt.loadFromFile("input.pptx");
for (int i = 0; i < ppt.getSlides().getCount(); i++)
{
ppt.getSlides().get(i).getShapes().addFromSVGAsShapes("in.svg");
}
ppt.saveToFile("output.pptx", FileFormat.PPTX_2013);
ppt.dispose();
问题修复:
问题修复:
Spire.Presentation 10.10.7 现已正式发布。该版本优化了使用模板创建 PPT 的保存时间。同时,新增了设置表格透明度的功能,并调整了 AddDigitalSignature 方法的使用方式,还修复了若干在转换 PPT 到 PDF 时内容不正确的问题。更多详情如下:
调整:
Presentation ppt = new Presentation();
ppt.LoadFromFile("in.pptx");
//Add a digital signature,The parameters: string certificatePath, string certificatePassword, string comments, DateTime signTime
ppt.AddDigitalSignature("test.pfx", "e-iceblue", "111", DateTime.Now);
ppt.SaveToFile("result.pptx", Spire.Presentation.FileFormat.Pptx2016);
ppt.Dispose();
新功能:
table.Fill.Transparency = 0.5f; // Value range is 1-0, table default color is black
// Need to set specific table color, set color code as follows:
table[0, 0].FillFormat.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
table[0, 0].FillFormat.SolidColor.Color = Color.Orange;
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html
Spire.PDF for Java 11.10.3 现已正式发布。该版本新增支持设置 PdfTable 的列宽。详情请阅读以下内容。
新功能:
// Create PDF document
PdfDocument doc = new PdfDocument();
// Set margins
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.setTop(unitCvtr.convertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point));
margin.setBottom(margin.getTop());
margin.setLeft(unitCvtr.convertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point));
margin.setRight(margin.getLeft());
// Add a page
PdfPageBase page = doc.getPages().add(PdfPageSize.A4, margin);
// Add table
PdfTable table = new PdfTable();
PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.black));
table.getStyle().setBorderPen(new PdfPen(brush, 0.5f));
table.getStyle().getHeaderStyle().setStringFormat(new PdfStringFormat(PdfTextAlignment.Center));
table.getStyle().setHeaderSource(PdfHeaderSource.Rows);
table.getStyle().setHeaderRowCount(1);
table.getStyle().setShowHeader(true);
table.getStyle().setCellPadding(2);
table.getStyle().setHeaderSource(PdfHeaderSource.Rows);
table.getStyle().setHeaderRowCount(1);
table.getStyle().setShowHeader(true);
// Set header font and style
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("SimSun", Font.PLAIN, 12));
table.getStyle().getHeaderStyle().setFont(font);
table.getStyle().getHeaderStyle().setBackgroundBrush(PdfBrushes.getCadetBlue());
PdfTrueTypeFont fontBody = new PdfTrueTypeFont(new Font("SimSun", Font.PLAIN, 10));
// Set even row font
table.getStyle().getDefaultStyle().setFont(fontBody);
// Set odd row font
table.getStyle().getAlternateStyle().setFont(fontBody);
// false: distribute by total width proportion, true: use set column width
table.getStyle().isFixWidth(true);
// Define data
String[] data = {"1;2;3;4;5",
"A1;B1;1,391,190,000;18.2%; ",
"A1;B1;126,490,000;1.66%; ",
"A1;B1;65,648,054;0.86%; ",
"A1;B1;82,665,600;1.08%; ",
"A1;B1;37,119,000;0.49%; ",
"A1;B1;327,216,000;4.29%; "
};
String[][] dataSource = new String[data.length][];
for (int i = 0; i < data.length; i++) {
dataSource[i] = data[i].split("[;]", -1);
}
table.setDataSource(dataSource);
for(int i = 0; i < table.getColumns().getCount(); i++)
{
PdfColumn column = table.getColumns().get(i);
column.setWidth(50);
column.setStringFormat(new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));
}
// Add table to page
table.draw(page, new Point2D.Float(0, 50));
// Save document
doc.saveToFile("addTable.pdf", FileFormat.PDF);
Spire.Doc for Java 13.10.6 现已正式发布。该版本获取样式更改修订,接受或拒绝部分修订,以及针对样式进行修订跟踪记录。同时,一些在转换 Word 到 PDF,加载和保存 Word 文档时出现的问题也已成功被修复。更多详情如下。
新功能:
Document document = new Document();
document.loadFromFile(inputFile);
RevisionInfoCollection revisionInfoCollection= document.getRevisionInfos();
for (int i = 0; i
Document document = ConvertUtil.GetNewEngineDocument();
document.loadFromFile(inputFile);
RevisionInfoCollection revisionInfoCollection= document.getRevisionInfos();
for (RevisionInfo revisionInfo : (java.lang.Iterable)revisionInfoCollection) {
if(revisionInfo.getRevisionType()==RevisionType.Format_Change){
if(revisionInfo.getOwnerObject() instanceof TextRange){
TextRange range = (TextRange)revisionInfo.getOwnerObject();
TestUtil.writeAllText(outputFile,"TextRange:"+range.getText()+"\r\n");
document.setRevisionsView(RevisionsView.Original);
TestUtil.writeAllText(outputFile,"Original bold:"+range.getCharacterFormat().getBold()+"\r\n");
document.setRevisionsView(RevisionsView.Final);
TestUtil.writeAllText(outputFile,"Final bold:"+range.getCharacterFormat().getBold()+"\r\n");
}
}
}
document.close();
Document document = new Document();
document.loadFromFile("http://cdn.e-iceblue.cn/test.docx");
document.startTrackRevisions("e-iceblue");
for (int i=0; i
sec.getPageSetup().setGridType(GridPitchType.Chars_And_Line);
sec.getPageSetup().setCharactersPerLine(30);
问题修复:
Spire.XLS for Java 15.10.5 现已正式发布。该版本优化了加载 Excel 文档时的内存消耗。同时,还修复了在获取复选框、加载大文件、复制工作表格式及保存文件等场景中出现的多个问题。更多详情如下:
优化:
问题修复:
Spire.XLS 15.10.3 现已发布。本次更新新增了默认支持读取 Office 缓存的云字体的功能,使其在支持系统字体目录和内存字体的基础上,能够自动识别和加载云字体。同时,本版本调整了 AddDigitalSignature() 和 IDigitalSignatures.Add() 方法的参数定义,并修复了多个已知问题,从而提升了整体的稳定性和兼容性。详细信息如下:
新功能:
调整:
原方法:
AddDigitalSignature(X509Certificate2 certificate, string comments, DateTime signTime)
新方法:
AddDigitalSignature(string certificatePath, string certificatePassword, string comments, DateTime signTime)
问题修复: