冰蓝科技
|
028-81705109
|
|
微信扫一扫
|

Spire.Cloud 纯前端文档控件

Spire.Doc for Java 10.11.6 已发布。此版本增强了 Word 到 PDF 的转换功能。同时此版本还修复了一些已知问题,如:修复了加载文档抛异常StringIndexOutOfBoundsException等问题。详情请阅读以下内容。

问题修复:


获取Spire.Doc for Java 10.11.6请点击:

https://www.e-iceblue.cn/Downloads/Spire-Doc-JAVA.html

Spire.Office 7.11.0 已发布。在本次更新中,Spire.PDF 支持压缩文档以及签名后锁住文档;Spire.Presentation 支持读取图表数据是否启用了“切换行/列”功能;Spire.Doc 增强了 Word 到 PDF 和 RTF 的转换;Spire.XLS 增强了 Excel 到 PDF 及 XML 到 Excel 的转换。此外,本次更新还成功修复了许多已知问题。详情请阅读以下内容。

该版本涵盖了最新版的 Spire.Doc,Spire.PDF,Spire.XLS,Spire.Email,Spire.DocViewer, Spire.PDFViewer,Spire.Presentation,Spire.Spreadsheet, Spire.OfficeViewer, Spire.DocViewer, Spire.Barcode, Spire.DataExport。

版本信息如下:

获取Spire.Office 7.11.0 请点击:

https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html


Spire.PDF

新功能:

问题修复:


Spire.Presentation

新功能:

问题修复:


Spire.Doc

问题修复:


Spire.XLS

问题修复:

Spire.Doc 10.11.0 已发布。本次更新增强了 Word 到 PDF 的转换。此外,该版本还修复了添加的自定义属性在 XML 里的标签名字和 MS Word 不一致等已知问题。详情请阅读以下内容。

问题修复:


获取 Spire.Doc 10.11.0 请点击:

https://www.e-iceblue.cn/Downloads/Spire-Doc-NET.html

Spire.PDF 8.11.0 已发布。本次更新支持文档压缩功能以及签名后锁住文档的功能。同时,该版本增强了 PDF 到 OFD、SVG 和图片的转换功能。此外,该版本还修复了一些已知问题,如合并PDF文档时程序抛出 NullReferenceException 异常的问题。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.PDF 8.11.0请点击:

https://www.e-iceblue.cn/Downloads/Spire-PDF-NET.html

当你在制作公司月度支出的 Word 报表时,你可能需要从 Excel 表格中复制财务数据到该报表,这样可以让别人直接在该报表里查看相关数据而无需打开另一个 Excel 文档。本文演示了如何使用 Spire.Office for .NET 在 C#/VB.NET 中将 Excel 数据转换为带格式的 Word 表格

安装 Spire. Office for .NET

首先,您需要添加 Spire.Office for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。

PM> Install-Package Spire.Office

将 Excel 数据转换为带格式的 Word 表格

以下是使用 Spire.Office for .NET 将 Excel 数据转换为 Word 表格并保留其格式的步骤。

  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Xls;

namespace ConvertExcelToWord
{
    internal class Program
    {
        static void Main(string[] args)
        {

            //加载一个示例 Excel 文件
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("企业经营数据表.xlsx");

            //获取特定的工作表
            Worksheet sheet = workbook.Worksheets[0];

            //创建一个 Document 对象
            Document doc = new Document();
            Section section = doc.AddSection();
            section.PageSetup.Orientation = PageOrientation.Landscape;

            //添加一个表格
            Table table = section.AddTable(true);
            table.ResetCells(sheet.LastRow, sheet.LastColumn);

            //合并单元格
            MergeCells(sheet, table);

            for (int r = 1; r <= sheet.LastRow; r++)
            {
                //设置行高
                table.Rows[r - 1].Height = (float)sheet.Rows[r - 1].RowHeight;

                for (int c = 1; c <= sheet.LastColumn; c++)
                {
                    CellRange xCell = sheet.Range[r, c];
                    TableCell wCell = table.Rows[r - 1].Cells[c - 1];

                    //将数据从 Excel 导出到 Word 表格
                    TextRange textRange = wCell.AddParagraph().AppendText(xCell.NumberText);

                    //将字体和单元格样式从 Excel 复制到 Word
                    CopyStyle(textRange, xCell, wCell);
                }
            }

            //将文档保存到 Word 文件
            doc.SaveToFile("导出到Word.docx", Spire.Doc.FileFormat.Docx);
        }
        //合并单元格(如果有)
        private static void MergeCells(Worksheet sheet, Table table)
        {
            if (sheet.HasMergedCells)
            {
                //从 Excel 获取合并的单元格范围
                CellRange[] ranges = sheet.MergedCells;

                //合并Word表格中对应的单元格
                for (int i = 0; i < ranges.Length; i++)
                {
                    int startRow = ranges[i].Row;
                    int startColumn = ranges[i].Column;
                    int rowCount = ranges[i].RowCount;
                    int columnCount = ranges[i].ColumnCount;
                    if (rowCount > 1 && columnCount > 1)
                    {
                        for (int j = startRow; j <= startRow + rowCount; j++)
                        {
                            table.ApplyHorizontalMerge(j - 1, startColumn - 1, startColumn - 1 + columnCount - 1);
                        }
                        table.ApplyVerticalMerge(startColumn - 1, startRow - 1, startRow - 1 + rowCount - 1);
                    }
                    if (rowCount > 1 && columnCount == 1)
                    {
                        table.ApplyVerticalMerge(startColumn - 1, startRow - 1, startRow - 1 + rowCount - 1);
                    }
                    if (columnCount > 1 && rowCount == 1)
                    {
                        table.ApplyHorizontalMerge(startRow - 1, startColumn - 1, startColumn - 1 + columnCount - 1);
                    }
                }
            }
        }

        //将Excel的单元格样式复制到Word表格
        private static void CopyStyle(TextRange wTextRange, CellRange xCell, TableCell wCell)
        {
            //复制字体样式
            wTextRange.CharacterFormat.TextColor = xCell.Style.Font.Color;
            wTextRange.CharacterFormat.FontSize = (float)xCell.Style.Font.Size;
            wTextRange.CharacterFormat.FontName = xCell.Style.Font.FontName;
            wTextRange.CharacterFormat.Bold = xCell.Style.Font.IsBold;
            wTextRange.CharacterFormat.Italic = xCell.Style.Font.IsItalic;
            //复制背景色
            wCell.CellFormat.BackColor = xCell.Style.Color;
            //复制水平对齐
            switch (xCell.HorizontalAlignment)
            {
                case HorizontalAlignType.Left:
                    wTextRange.OwnerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
                    break;
                case HorizontalAlignType.Center:
                    wTextRange.OwnerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center;
                    break;
                case HorizontalAlignType.Right:
                    wTextRange.OwnerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Right;
                    break;
            }
            //复制垂直对齐
            switch (xCell.VerticalAlignment)
            {
                case VerticalAlignType.Bottom:
                    wCell.CellFormat.VerticalAlignment = VerticalAlignment.Bottom;
                    break;
                case VerticalAlignType.Center:
                    wCell.CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    break;
                case VerticalAlignType.Top:
                    wCell.CellFormat.VerticalAlignment = VerticalAlignment.Top;
                    break;
            }
        }
    }
}
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Xls

Namespace ConvertExcelToWord
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())

            '加载一个示例 Excel 文件
            Dim workbook As Workbook = New Workbook()
            workbook.LoadFromFile("企业经营数据表.xlsx")

            '获取特定的工作表
            Dim sheet As Worksheet = workbook.Worksheets(0)

            '创建一个 Document 对象
            Dim doc As Document = New Document()
            Dim section As Section = doc.AddSection()
            section.PageSetup.Orientation = PageOrientation.Landscape

            '添加一个表格
            Dim table As Table = section.AddTable(True)
            table.ResetCells(sheet.LastRow, sheet.LastColumn)

            '合并单元格
            Program.MergeCells(sheet, table)

            For r As Integer = 1 To sheet.LastRow
                '设置行高
                table.Rows(r - 1).Height = CSng(sheet.Rows(r - 1).RowHeight)

                For c As Integer = 1 To sheet.LastColumn
                    Dim xCell As CellRange = sheet.Range(r, c)
                    Dim wCell As TableCell = table.Rows(r - 1).Cells(c - 1)

                    '将数据从 Excel 导出到 Word 表格
                    Dim textRange As TextRange = wCell.AddParagraph().AppendText(xCell.NumberText)

                    '将字体和单元格样式从 Excel 复制到 Word
                    Program.CopyStyle(textRange, xCell, wCell)
                Next
            Next

            '将文档保存到 Word 文件
            doc.SaveToFile("导出到Word.docx", Spire.Doc.FileFormat.Docx)
        End Sub
        '合并单元格(如果有)
        Private Shared Sub MergeCells(ByVal sheet As Worksheet, ByVal table As Table)
            If sheet.HasMergedCells Then
                '从 Excel 获取合并的单元格范围
                Dim ranges As CellRange() = sheet.MergedCells

                '合并Word表格中对应的单元格
                For i = 0 To ranges.Length - 1
                    Dim startRow As Integer = ranges(i).Row
                    Dim startColumn As Integer = ranges(i).Column
                    Dim rowCount As Integer = ranges(i).RowCount
                    Dim columnCount As Integer = ranges(i).ColumnCount
                    If rowCount > 1 AndAlso columnCount > 1 Then
                        For j = startRow To startRow + rowCount
                            table.ApplyHorizontalMerge(j - 1, startColumn - 1, startColumn - 1 + columnCount - 1)
                        Next
                        table.ApplyVerticalMerge(startColumn - 1, startRow - 1, startRow - 1 + rowCount - 1)
                    End If
                    If rowCount > 1 AndAlso columnCount = 1 Then
                        table.ApplyVerticalMerge(startColumn - 1, startRow - 1, startRow - 1 + rowCount - 1)
                    End If
                    If columnCount > 1 AndAlso rowCount = 1 Then
                        table.ApplyHorizontalMerge(startRow - 1, startColumn - 1, startColumn - 1 + columnCount - 1)
                    End If
                Next
            End If
        End Sub

        '将Excel的单元格样式复制到Word表格
        Private Shared Sub CopyStyle(ByVal wTextRange As TextRange, ByVal xCell As CellRange, ByVal wCell As TableCell)
            '复制字体样式
            wTextRange.CharacterFormat.TextColor = xCell.Style.Font.Color
            wTextRange.CharacterFormat.FontSize = CSng(xCell.Style.Font.Size)
            wTextRange.CharacterFormat.FontName = xCell.Style.Font.FontName
            wTextRange.CharacterFormat.Bold = xCell.Style.Font.IsBold
            wTextRange.CharacterFormat.Italic = xCell.Style.Font.IsItalic
            '复制背景色
            wCell.CellFormat.BackColor = xCell.Style.Color
            '复制水平对齐
            Select Case xCell.HorizontalAlignment
                Case HorizontalAlignType.Left
                    wTextRange.OwnerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Left
                Case HorizontalAlignType.Center
                    wTextRange.OwnerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center
                Case HorizontalAlignType.Right
                    wTextRange.OwnerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Right
            End Select
            '复制垂直对齐
            Select Case xCell.VerticalAlignment
                Case VerticalAlignType.Bottom
                    wCell.CellFormat.VerticalAlignment = VerticalAlignment.Bottom
                Case VerticalAlignType.Center
                    wCell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
                Case VerticalAlignType.Top
                    wCell.CellFormat.VerticalAlignment = VerticalAlignment.Top
            End Select
        End Sub
    End Class
End Namespace

C#/VB.NET 将 Excel 数据转换为带格式的 Word 表格

申请临时 License

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。

Spire.PDF for Java 8.11.0已发布。该版本支持设置打印页面范围,并且增强了PDF到Word的转换功能。此外还修复了添加注释位置不正确等已知问题。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.PDF for Java 8.11.0请点击:

https://www.e-iceblue.cn/Downloads/Spire-PDF-JAVA.html

Spire.Presentation 7.10.2 已发布。该版本支持读取图表数据是否启用了“切换行/列”功能。同时,该版本还修复了转换 PPT 到 PDF 后背景色不正确的问题。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.Presentation 7.10.2请点击:

https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html

Spire.Office for Java 7.10.4 已发布。本次更新带来了一些新功能,如:Spire.Doc for Java 支持设置Word文档网格属性,并支持以流的方式判断docm格式的文件是否被加密。 同时,Spire.PDF for Java增强了 PDF 到图片的转换;Spire.XLS for Java增强了 Excel 到 PDF 的转换;Spire.Presentation for Java增强了 PPT 到 PDF、SVG 及图片的转换。此外,该版本还成功修复了许多已知问题。详情请阅读以下内容。

获取 Spire.Office for Java 7.10.4请点击:

https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html


Spire.Doc for Java

新功能:

问题修复:


Spire.PDF for Java

问题修复:


Spire.XLS for Java

问题修复:


Spire.Presentation for Java

问题修复:

Spire.Doc for Java 10.10.7 已发布。本次更新新增支持设置Word文档网格属性及以流的方式判断 docm 格式的文件是否被加密。同时,该版本增强了 Word 到 PDF、Word 到 HTML、HTML 到 Word 和 Docm 到 Docx 的转换。此外,版本还修复了许多已知问题,如:邮件合并域更新不正确以及更新目录域程序抛异常“unpected cross ax”的问题。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.Doc for Java 10.10.7请点击:

https://www.e-iceblue.cn/Downloads/Spire-Doc-JAVA.html

页码对于电子文档和纸质文档都是必不可少的。 它们可以使读者更容易快速查找和访问文档的特定部分,而无需逐页浏览。 在本文中,您将学习如何使用 Spire.PDF for .NET 将页码添加到现有 PDF 文档中

安装 Spire.PDF for .NET

首先,您需要添加 Spire.PDF for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。

PM> Install-Package Spire.PDF

将页码添加到现有 PDF 文档

您可以使用以下动态字段向 PDF 文档添加页码:PdfPageNumberFieldPdfPageCountFieldPdfCompositeField

顾名思义,PdfPageNumberField 用于显示页码,PdfPageCountField 用于显示总页数,PdfCompositeField 用于将PdfPageNumberField 和 PdfPageCountField 等两个或多个动态字段组合成一个字段。

如果您只想将第 1 页、第 2 页、第 3 页等页码添加到 PDF 文档,您可以使用 PdfPageNumberField。 如果您想在文档中添加“第 X 页,共 Y 页”页码,您需要使用 PdfPageNumberField、PdfPageCountField 和 PdfCompositeField。

以下步骤向您展示如何将“第 X 页,共 Y 页”页码添加到现有 PDF 文档:

  • C#
  • VB.NET
using Spire.Pdf;
using Spire.Pdf.AutomaticFields;
using Spire.Pdf.Graphics;
using System.Drawing;


namespace AddPageNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化 PdfDocument 类的实例
            PdfDocument pdf = new PdfDocument();

            //加载示例文档
            pdf.LoadFromFile("示例文档.pdf");

            //设置页码字体样式
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("宋体", 10f, FontStyle.Regular), true);

            //初始化 PdfPageNumberField 类的实例
            PdfPageNumberField pageNumber = new PdfPageNumberField();

            //初始化PdfPageCountField 类的实例
            PdfPageCountField pageCount = new PdfPageCountField();

            //初始化PdfCompositeField 类的实例
            PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.Black, "第{0}页,共{1}页", pageNumber, pageCount);
            //设置复合字段的文本对齐方式
            compositeField.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);

            //循环遍历页面
            for (int i = 0; i < pdf.Pages.Count; i++)
            {
                //在页面的特定位置绘制复合字段
                compositeField.Draw(pdf.Pages[i].Canvas, pdf.Pages[i].Size.Width / 4 - 20, pdf.Pages[i].Size.Height / 2- 20);
            }

            //保存结果文档
            pdf.SaveToFile("添加页码.pdf");
        }
    }
}
Imports Spire.Pdf
Imports Spire.Pdf.AutomaticFields
Imports Spire.Pdf.Graphics

Namespace AddPageNumbers
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            '初始化 PdfDocument 类的实例
            Dim pdf As PdfDocument = New PdfDocument()

            '加载示例文档
            pdf.LoadFromFile("示例文档.pdf")

            '设置页码字体样式
            Dim font As PdfTrueTypeFont = New PdfTrueTypeFont(New Font("宋体", 10F, FontStyle.Regular), True)

            '初始化 PdfPageNumberField 类的实例
            Dim pageNumber As PdfPageNumberField = New PdfPageNumberField()

            '初始化PdfPageCountField 类的实例
            Dim pageCount As PdfPageCountField = New PdfPageCountField()

            '初始化PdfCompositeField 类的实例
            Dim compositeField As PdfCompositeField = New PdfCompositeField(font, PdfBrushes.Black, "第{0}页,共{1}页", pageNumber, pageCount)
            '设置复合字段的文本对齐方式
            compositeField.StringFormat = New PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top)

            '循环遍历页面
            For i As Integer = 0 To pdf.Pages.Count - 1
                '在页面的特定位置绘制复合字段
                compositeField.Draw(pdf.Pages(i).Canvas, pdf.Pages(i).Size.Width / 4 - 20, pdf.Pages(i).Size.Height / 2 - 20)
            Next

            '保存结果文档
            pdf.SaveToFile("添加页码.pdf")
        End Sub
    End Class
End Namespace

C#/VB.NET 将页码添加到现有 PDF 文档

申请临时 License

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。