Spire.Office 6.3.3已发布。本次更新带了一些新的功能,譬如:Spire PDF 支持添加 page-piece 字典,新增移除表单域的功能;Spire.XLS支持修改透视表的数据源并且新增设置形状顺序的功能等等。此外,该版本还修复了大量问题。详情请阅读以下内容。
该版本涵盖了最新版的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
新功能:
PdfDocument doc = new PdfDocument(inputFile);
if (doc.DocumentPieceInfo==null) {
doc.DocumentPieceInfo = new PdfPieceInfo();
}
doc.DocumentPieceInfo.AddApplicationData("ice","this is a uu");
doc.DocumentPieceInfo.AddApplicationData("blie", "this is a uu");
doc.DocumentPieceInfo.AddApplicationData("blue", "this is a uu");
doc.DocumentPieceInfo.AddApplicationData("jis", "this is a uu");
doc.DocumentPieceInfo.RemoveApplicationData("blie");
if (doc.Pages[0].PagePieceInfo==null) {
doc.Pages[0].PagePieceInfo = new PdfPieceInfo();
}
doc.Pages[0].PagePieceInfo.AddApplicationData("ice", "this is a uu");
doc.Pages[0].PagePieceInfo.AddApplicationData("blie", "this is a 2222uu");
doc.Pages[0].PagePieceInfo.AddApplicationData("blue", "this is a 3333uu");
doc.Pages[0].PagePieceInfo.AddApplicationData("jis", "this is a 4444uu");
doc.Pages[0].PagePieceInfo.RemoveApplicationData("blie");
StringBuilder sb = new StringBuilder();
IDictionary<sstring, PdfApplicationData> dic = doc.Pages[0].PagePieceInfo.ApplicationDatas;
foreach (string item in dic.Keys) {
PdfApplicationData data = dic[item];
if (data.Private is String) {
string ss = data.Private as string;
sb.AppendLine(ss);
}
}
File.WriteAllText(outputFile_txt, sb.ToString());
doc.SaveToFile(outputFile);
string input = @"Field.pdf";
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(input);
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
if (formWidget != null)
{
//方法 1
//formWidget.FieldsWidget.Clear();
for (int i = formWidget.FieldsWidget.List.Count - 1; i >= 0; i--)
{
//方法 2
PdfField field = formWidget.FieldsWidget.List[i] as PdfField; formWidget.FieldsWidget.Remove(field);
}
}
string output = "DeleteFormField.pdf";
doc.SaveToFile(output);
PdfDocument doc = new PdfDocument();
MemoryStream stream = new MemoryStream(File.ReadAllBytes("test.pdf"));
doc.Collection.AddFile("file.pdf", stream);
doc.SaveToFile("result.pdf");
问题修复:
新功能:
var pivotTable = sheet.PivotTables[0];
((Spire.Xls.PivotTable)pivotTable).ChangeDataSource(sheet.Range["A1:C9"]);
wb.Worksheets[0].Pictures[0].ChangeLayer(ShapeLayerChangeType.BringForward);
wb.Worksheets[1].Pictures[0].ChangeLayer(ShapeLayerChangeType.BringToFront);
wb.Worksheets[2].Pictures[1].ChangeLayer(ShapeLayerChangeType.SendBackward);
wb.Worksheets[3].Pictures[1].ChangeLayer(ShapeLayerChangeType.SendToBack);
//拷贝workbook的theme
workbook.CopyTheme(srcWorkbook);
//设置workbook中默认theme的某一类型颜色
workbook.SetThemeColor(ThemeColorType.Accent1, Color.Blue);
//获取workbook中默认theme的某一类型颜色
Color color = workbook.GetThemeColor(ThemeColorType.Accent2);
//设置style 为theme color
style.SetThemeColor(ThemeColorType.Lt1, 0.1);
//获取style的themeColor(type ,tint)
bool isThemeColor = style.GetThemeColor(out themeType, out tint);
sheet.GetFreezePanes(out rowIndex, out colIndex);
问题修复:
问题修复:
问题修复:
本文介绍使用Spire.Doc for .NET读取Word文本框的方法。可读取文本框中的文本、图片和表格等,读取表格请参考这篇文章。文本内容位为读取文本和图片。
用于测试的Word源文档如图:

1、读取文本框中的文本
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.IO;
using System.Text;
namespace ExtractText
{
class Program
{
static void Main(string[] args)
{
//加载Word源文档
Document doc = new Document();
doc.LoadFromFile("https://cdn.e-iceblue.cn/sample.docx");
//获取文本框
TextBox textbox = doc.TextBoxes[0];
//创建StringBuilder类的对象
StringBuilder sb = new StringBuilder();
//遍历文本框中的对象,获取文本
foreach (object obj in textbox.Body.ChildObjects)
{
if (obj is Paragraph)
{
String text = ((Paragraph)obj).Text;
sb.AppendLine(text);
}
}
//保存写入的txt文档到指定路径
File.WriteAllText("ExtractedText.txt", sb.ToString());
System.Diagnostics.Process.Start("ExtractedText.txt");
}
}
}
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.IO
Imports System.Text
Namespace ExtractText
Class Program
Private Shared Sub Main(args As String())
'加载Word源文档
Dim doc As New Document()
doc.LoadFromFile("https://cdn.e-iceblue.cn/sample.docx")
'获取文本框
Dim textbox As TextBox = doc.TextBoxes(0)
'创建StringBuilder类的对象
Dim sb As New StringBuilder()
'遍历文本框中的对象,获取文本
For Each obj As Object In textbox.Body.ChildObjects
If TypeOf obj Is Paragraph Then
Dim text As [String] = DirectCast(obj, Paragraph).Text
sb.AppendLine(text)
End If
Next
'保存写入的txt文档到指定路径
File.WriteAllText("ExtractedText.txt", sb.ToString())
System.Diagnostics.Process.Start("ExtractedText.txt")
End Sub
End Class
End Namespace
文本读取结果:

2、读取文本框中的图片
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
namespace ExtractImg
{
class Program
{
static void Main(string[] args)
{
//加载Word源文档
Document doc = new Document();
doc.LoadFromFile("https://cdn.e-iceblue.cn/sample.docx");
//获取文本框
TextBox textbox = doc.TextBoxes[0];
int index = 0 ;
//遍历文本框中所有段落
for (int i = 0 ; i < textbox.Body.Paragraphs.Count;i++)
{
Paragraph paragraph = textbox.Body.Paragraphs[i];
//遍历段落中的所有子对象
for (int j = 0; j < paragraph.ChildObjects.Count; j++)
{
object obj = paragraph.ChildObjects[j];
//判定对象是否为图片
if (obj is DocPicture)
{
//获取图片
DocPicture picture = (DocPicture) obj;
String imageName = String.Format("Image-{0}.png", index);
picture.Image.Save(imageName, System.Drawing.Imaging.ImageFormat.Png);
index++;
}
}
}
}
}
}
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace ExtractImg
Class Program
Private Shared Sub Main(args As String())
'加载Word源文档
Dim doc As New Document()
doc.LoadFromFile("https://cdn.e-iceblue.cn/sample.docx")
'获取文本框
Dim textbox As TextBox = doc.TextBoxes(0)
Dim index As Integer = 0
'遍历文本框中所有段落
For i As Integer = 0 To textbox.Body.Paragraphs.Count - 1
Dim paragraph As Paragraph = textbox.Body.Paragraphs(i)
'遍历段落中的所有子对象
For j As Integer = 0 To paragraph.ChildObjects.Count - 1
Dim obj As Object = paragraph.ChildObjects(j)
'判定对象是否为图片
If TypeOf obj Is DocPicture Then
'获取图片
Dim picture As DocPicture = DirectCast(obj, DocPicture)
Dim imageName As [String] = [String].Format("Image-{0}.png", index)
picture.Image.Save(imageName, System.Drawing.Imaging.ImageFormat.Png)
index += 1
End If
Next
Next
End Sub
End Class
End Namespace
图片读取结果:

Spire.Doc 9.3.3已发布。该版本增强了转换Word到PDF/图片,以及RTF/XML/HTML到PDF的功能。 此外,本次版本更新还修复了加载Word文档时出现的问题。详情请阅读以下内容。
问题修复:
Spire.XLS 11.3.4已发布。该版本支持设置形状顺序,支持操作工作表主题,同时新增了获取冻结窗格单元格范围的功能。此外,该版本增强了转换Excel到图片/PDF的功能,并且修复了保存Excel文档时出现的问题。详情请阅读以下内容。
新功能:
wb.Worksheets[0].Pictures[0].ChangeLayer(ShapeLayerChangeType.BringForward);
wb.Worksheets[1].Pictures[0].ChangeLayer(ShapeLayerChangeType.BringToFront);
wb.Worksheets[2].Pictures[1].ChangeLayer(ShapeLayerChangeType.SendBackward);
wb.Worksheets[3].Pictures[1].ChangeLayer(ShapeLayerChangeType.SendToBack);
//拷贝workbook的theme
workbook.CopyTheme(srcWorkbook);
//设置workbook中默认theme的某一类型颜色
workbook.SetThemeColor(ThemeColorType.Accent1, Color.Blue);
//获取workbook中默认theme的某一类型颜色
Color color = workbook.GetThemeColor(ThemeColorType.Accent2);
//设置style 为theme color
style.SetThemeColor(ThemeColorType.Lt1, 0.1);
//获取style的themeColor(type ,tint)
bool isThemeColor = style.GetThemeColor(out themeType, out tint);
sheet.GetFreezePanes(out rowIndex, out colIndex);
问题修复:
Spire.PDF 7.3.1已发布。该版本支持了移除表单域,同时也支持从stream流中添加PDF文档到PDF文件包,增强了转换PDF到Word/图片/ PDF/A-3A的功能。此外,该版本还修复了提取和替换文本时出现的问题等。详情请阅读以下内容。
新功能:
string input = @"Field.pdf";
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(input);
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
if (formWidget != null)
{
//方法 1
//formWidget.FieldsWidget.Clear();
for (int i = formWidget.FieldsWidget.List.Count - 1; i >= 0; i--)
{
//方法 2
PdfField field = formWidget.FieldsWidget.List[i] as PdfField; formWidget.FieldsWidget.Remove(field);
}
}
string output = "DeleteFormField.pdf";
doc.SaveToFile(output);
PdfDocument doc = new PdfDocument();
MemoryStream stream = new MemoryStream(File.ReadAllBytes("test.pdf"));
doc.Collection.AddFile("file.pdf", stream);
doc.SaveToFile("result.pdf");
问题修复:
本文将详细介绍如何在Java应用程序中给PowerPoint文档添加多行多列文本水印。
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class WatermarkDemo {
public static void main(String[] args) throws Exception {
Presentation presentation = new Presentation();
presentation.loadFromFile("Sample.pptx");
//设置文本水印的宽和高
int width= 300;
int height= 200;
//绘制文本,设置文本格式并将其添加到第一张幻灯片
float x = 30;
float y = 80;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Rectangle2D.Double rect = new Rectangle2D.Double(x,y,width, height);
//添加一个shape到定义区域
IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rect);
//设置shape样式
shape.getFill().setFillType(FillFormatType.NONE);
shape.getShapeStyle().getLineColor().setColor(Color.white);
shape.setRotation(-45);
shape.getLocking().setSelectionProtection(true);
shape.getLine().setFillType(FillFormatType.NONE);
//添加文本到shape
shape.getTextFrame().setText("内部使用");
PortionEx textRange = shape.getTextFrame().getTextRange();
//设置文本水印样式
textRange.getFill().setFillType(FillFormatType.SOLID);
textRange.getFill().getSolidColor().setColor(Color.pink);
textRange.setFontHeight(20);
x += (100 + presentation.getSlideSize().getSize().getWidth()/5);
}
x = 30;
y += (100 + presentation.getSlideSize().getSize().getHeight()/6);
}
//保存文档
presentation.saveToFile("output/result.pptx", FileFormat.PPTX_2010);
}
}
效果图:

本文介绍使用Spire.Doc for Java来读取Word文本框的方法,读取时,可读取文本框中的文本、图片、表格等。其中,读取文本框中的表格可以参考这篇文章。以下内容为读取文本和图片。
用于测试的Word源文档如下图:

1、读取文本框中的文本
import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.TextBox;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class ExtractText {
public static void main(String[] args) throws IOException {
//加载含有文本框的Word文档
Document doc = new Document();
doc.loadFromFile("https://cdn.e-iceblue.cn/test.docx");
//获取文本框
TextBox textbox = doc.getTextBoxes().get(0);
//保存文本框中的文本到指定文件
File file = new File("ExtractedText.txt");
if (file.exists())
{
file.delete();
}
file.createNewFile();
FileWriter fw = new FileWriter(file, true);
BufferedWriter bw = new BufferedWriter(fw);
//遍历文本框中的对象
for (Object object:textbox.getBody().getChildObjects())
{
//判定是否为文本段落
if(object instanceof Paragraph)
{
//获取段落中的文本
String text = ((Paragraph) object).getText();
//写入文本到txt文档
bw.write(text);
}
}
bw.flush();
bw.close();
fw.close();
}
}
文本读取结果:

2、读取文本框中的图片
import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.DocPicture;
import com.spire.doc.fields.TextBox;
import javax.imageio.ImageIO;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ExtractImg {
public static void main(String[] args) throws IOException {
//加载含有文本框的Word文档
Document doc = new Document();
doc.loadFromFile("https://cdn.e-iceblue.cn/test.docx");
//获取文本框
TextBox textbox = doc.getTextBoxes().get(0);
//创建List对象
ArrayList<BufferedImage> images = new ArrayList();
//遍历文本框中所有段落
for (int i = 0 ; i < textbox.getBody().getParagraphs().getCount();i++)
{
Paragraph paragraph = textbox.getBody().getParagraphs().get(i);
//遍历段落中的所有子对象
for (int j = 0; j < paragraph.getChildObjects().getCount(); j++)
{
Object object = paragraph.getChildObjects().get(j);
//判定对象是否为图片
if (object instanceof DocPicture)
{
//获取图片
DocPicture picture = (DocPicture) object;
images.add(picture.getImage());
}
}
}
//将图片以PNG文件格式保存
for (int z = 0; z < images.size(); z++) {
File file = new File(String.format("图片-%d.png", z));
ImageIO.write(images.get(z), "PNG", file);
}
}
}
图片读取结果:

Spire.Spreadsheet 5.3.0已发布。该版本主要修复了文本和数字的显示问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Spreadsheet-NET.html
该文将详细介绍在保存Excel工作簿到PDF文档时,在 PDF 结果文档中添加页码。
using Spire.Xls;
namespace ExcelDemo
{
class Program
{
static void Main(string[] args)
{
//加载示例文档
Workbook wbk = new Workbook();
wbk.LoadFromFile("Sample.xlsx");
foreach (Worksheet sheet in wbk.Worksheets)
{
//&P 指Page Number, &N 指总页数
sheet.PageSetup.RightFooter = "&P/&N";
}
//保存文档
wbk.SaveToFile("Result.pdf", FileFormat.PDF);
}
}
}
Imports Spire.Xls
Namespace ExcelDemo
Class Program
Private Shared Sub Main(ByVal args() As String)
'加载示例文档
Dim wbk As Workbook = New Workbook
wbk.LoadFromFile("Sample.xlsx")
For Each sheet As Worksheet In wbk.Worksheets
'&P 指Page Number, &N 指总页数
sheet.PageSetup.RightFooter = "&P/&N"
Next
'保存文档
wbk.SaveToFile("Result.pdf", FileFormat.PDF)
End Sub
End Class
End Namespace
效果图:

本文介绍如何使用Spire.Doc for Java给Word添加行号。
import com.spire.doc.*;
public class AddLineNumber {
public static void main(String[] args) {
//加载Word文档
Document doc = new Document();
doc.loadFromFile("https://cdn.e-iceblue.cn/test.docx");
//遍历Word中的所有section
for(int i = 0; i < doc.getSections().getCount();i++)
{
Section section = doc.getSections().get(i);//获取所有section
section.getPageSetup().setLineNumberingStartValue(1);//设置行号起始编号
section.getPageSetup().setLineNumberingDistanceFromText(35);//设置行号距离正文距离
section.getPageSetup().setLineNumberingStep(1);//设置行号间隔
section.getPageSetup().setLineNumberingRestartMode(LineNumberingRestartMode.Restart_Section);//设置行号的编号模式
}
//保存文档
doc.saveToFile("AddLineNumber.docx",FileFormat.Docx_2013);//保存文档
}
}
行号添加效果:
