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

Spire.Cloud 纯前端文档控件

Tab 1

此 Demo 展示如何在 Word 文档中搜索文本并高亮显示匹配的文本。

Upload

Maximum file size: 1 MB. Files accepted: doc, docx, txt, rtf.
Click here to browse files.
fileerrors

Convert to

Source file:
filename
Search Text:

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

using System;
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace DemoOnlineCode
{
    class FindAndHighlight
    {
        public void demoFindAndHighlight(String docFile, String searchText)
        {
            Document document = new Document(docFile, FileFormat.Auto);

            TextSelection[] textSelections
                = document.FindAllString(searchText, false, false);
            if (textSelections != null)
            {
                foreach (TextSelection selection in textSelections)
                {
                    TextRange textMatched = selection.GetAsOneRange();
                    textMatched.CharacterFormat.HighlightColor = Color.Yellow;
                }
            }

            document.SaveToFile("demo.doc", FileFormat.Doc);
        }
    }
}

Tab 3

Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace DemoOnlineCode
    Class FindAndHighlight
        Public Sub demoFindAndHighlight(docFile As [String], searchText As [String])
            Dim document As New Document(docFile, FileFormat.Auto)

            Dim textSelections As TextSelection() = document.FindAllString(searchText, False, False)
            If textSelections IsNot Nothing Then
                For Each selection As TextSelection In textSelections
                    Dim textMatched As TextRange = selection.GetAsOneRange()
                    textMatched.CharacterFormat.HighlightColor = Color.Yellow
                Next
            End If

            document.SaveToFile("demo.doc", FileFormat.Doc)
        End Sub
    End Class
End Namespace

Tab 1

此 Demo 展示如何将 Word 文档 (doc/docx) 转换为 PDF、HTML、Image、XPS、RTF 和 TIFF 文件格式。

Upload

Maximum file size: 1 MB. Files accepted: doc, docx, txt, rtf.
Click here to browse files.
fileerrors

Convert to

Source file:
filename
Target file type:

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

using System;
using System.Drawing;
using System.Drawing.Imaging;

using Spire.Doc;
using Spire.Doc.Documents;

namespace DemoOnlineCode
{
    class Convertors
    {
        public void demoConversion(String docFile, string format)
        {
            Document document = new Document(docFile, FileFormat.Auto);
            ConvertFormat(document, format);
        }

        private void ConvertFormat(Document document, string format)
        {
            switch (format)
            {
                case "PDF":
                    document.SaveToFile("demo.pdf", FileFormat.PDF);
                    break;

                case "XPS":
                    document.SaveToFile("demo.xps", FileFormat.XPS);
                    break;

                case "Image":
                    Image[] Images = document.SaveToImages(ImageType.Bitmap);
                    if (Images != null && Images.Length > 0)
                    {
                        if (Images.Length == 1)
                        {
                            Images[0].Save("demo.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                        }
                        else
                        {
                            for (int i = 0; i < Images.Length; i++)
                            {
                                String fileName = String.Format("Image-{0}.png", i);
                                Images[i].Save(fileName, ImageFormat.Png);
                            }
                        }
                    }
                    break;
                case "RTF":
                    document.SaveToFile("demo.rtf", FileFormat.Rtf);
                    break;
                case "TIFF":
                    Image[] TiffImage = document.SaveToImages(ImageType.Bitmap);

                    Image result = JoinTiffImages(TiffImage, EncoderValue.CompressionLZW);
                    result.Save("demo.tiff", ImageFormat.Tiff);
                    break;
                case "HTML":
                    document.SaveToFile("demo.html", FileFormat.Html);
                    break;
            }
        }

        private static Image JoinTiffImages(Image[] images, EncoderValue compressEncoder)
        {

            //use the save encoder
            Encoder enc = Encoder.SaveFlag;
            EncoderParameters ep = new EncoderParameters(2);
            ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
            ep.Param[1] = new EncoderParameter(Encoder.Compression, (long)compressEncoder);

            Image pages = null;
            int frame = 0;
            ImageCodecInfo info = GetEncoderInfo("image/tiff");

            foreach (Image img in images)
            {
                if (frame == 0)
                {
                    pages = img;
                    pages.Save("demo.tiff", info, ep);
                }
                else
                {
                    //save the intermediate frames
                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);

                    pages.SaveAdd(img, ep);

                }

                if ((frame == images.Length - 1) && frame != 0)
                {
                    //flush and close.
                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
                    pages.SaveAdd(ep);
                }

                frame++;
            }
            return pages;
        }

        private static ImageCodecInfo GetEncoderInfo(string mimeType)
        {
            ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
            for (int j = 0; j < encoders.Length; j++)
            {
                if (encoders[j].MimeType == mimeType)
                    return encoders[j];
            }

            throw new Exception(mimeType + " mime type not found in ImageCodecInfo");
        }
    }

}

Tab 3

Imports System.Drawing
Imports System.Drawing.Imaging

Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace DemoOnlineCode
    Class Convertors
        Public Sub demoConversion(docFile As [String], format As String)
            Dim document As New Document(docFile, FileFormat.Auto)
            ConvertFormat(document, format)
        End Sub

        Private Sub ConvertFormat(document As Document, format As String)
            Select Case format
                Case "PDF"
                    document.SaveToFile("demo.pdf", FileFormat.PDF)
                    Exit Select

                Case "XPS"
                    document.SaveToFile("demo.xps", FileFormat.XPS)
                    Exit Select

                Case "Image"
                    Dim Images As Image() = document.SaveToImages(ImageType.Bitmap)
                    If Images IsNot Nothing AndAlso Images.Length > 0 Then
                        If Images.Length = 1 Then
                            Images(0).Save("demo.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
                        Else
                            For i As Integer = 0 To Images.Length - 1
                                Dim fileName As [String] = [String].Format("Image-{0}.png", i)
                                Images(i).Save(fileName, ImageFormat.Png)
                            Next
                        End If
                    End If
                    Exit Select
                Case "RTF"
                    document.SaveToFile("demo.rtf", FileFormat.Rtf)
                    Exit Select
                Case "TIFF"
                    Dim TiffImage As Image() = document.SaveToImages(ImageType.Bitmap)

                    Dim result As Image = JoinTiffImages(TiffImage, EncoderValue.CompressionLZW)
                    result.Save("demo.tiff", ImageFormat.Tiff)
                    Exit Select
                Case "HTML"
                    document.SaveToFile("demo.html", FileFormat.Html)
                    Exit Select
            End Select
        End Sub

        Private Shared Function JoinTiffImages(images As Image(), _
                                               compressEncoder As EncoderValue) As Image

            'use the save encoder
            Dim enc As Encoder = Encoder.SaveFlag
            Dim ep As New EncoderParameters(2)
            ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.MultiFrame))
            ep.Param(1) = New EncoderParameter(Encoder.Compression, CLng(compressEncoder))

            Dim pages As Image = Nothing
            Dim frame As Integer = 0
            Dim info As ImageCodecInfo = GetEncoderInfo("image/tiff")

            For Each img As Image In images
                If frame = 0 Then
                    pages = img
                    pages.Save("demo.tiff", info, ep)
                Else
                    'save the intermediate frames
                    ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.FrameDimensionPage))
                    pages.SaveAdd(img, ep)
                End If

                If (frame = images.Length - 1) AndAlso frame <> 0 Then
                    'flush and close.
                    ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
                    pages.SaveAdd(ep)
                End If

                frame += 1
            Next
            Return pages
        End Function

        Private Shared Function GetEncoderInfo(mimeType As String) As ImageCodecInfo
            Dim encoders As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
            For j As Integer = 0 To encoders.Length - 1
                If encoders(j).MimeType = mimeType Then
                    Return encoders(j)
                End If
            Next

            Throw New Exception(mimeType & " mime type not found in ImageCodecInfo")
        End Function
    End Class

End Namespace

Spire.Presentation for Java 4.8.4已发布。本次更新修复了给PPTX文档添加批注时出现的问题,同时还修复了添加的项目列表符号不正确的问题。详情请阅读以下内容。

问题修复:


获取Spire.Presentation for Java 4.8.4请点击:

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

本文将介绍如何使用Spire.XLS for Java设置Excel单元格文字自动换行和取消自动换行。

原Excel文档:

Java 设置 Excel 单元格文字自动换行和取消自动换行

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class WrapOrUnwrapText {
    public static void main(String []args) throws Exception {
        //创建Workbook实例
        Workbook workbook = new Workbook();
        //加载Excel文档
        workbook.loadFromFile("Input.xlsx");

        //获取第一张工作表
        Worksheet sheet = workbook.getWorksheets().get(0);

        //设置单元格"A1"的文字自动换行
        sheet.getRange().get("A1").getStyle().setWrapText(true);

        //取消单元格"A6"的文字自动换行
        sheet.getRange().get("A6").getStyle().setWrapText(false);

        //保存文档
        workbook.saveToFile("WrapOrUnwrapText.xlsx", ExcelVersion.Version2013);
    }
}

结果Excel文档:

Java 设置 Excel 单元格文字自动换行和取消自动换行

本文介绍使用Spire.XLS for .NET来压缩Excel工作表中的图片。

C#
using Spire.Xls;

namespace CompressImgs
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载Excel测试文档
            Workbook wb = new Workbook();
            wb.LoadFromFile("test.xlsx");

            //遍历工作表
            foreach (Worksheet sheet in wb.Worksheets)
            {
                //遍历工作表中的所有图片
                foreach (ExcelPicture picture in sheet.Pictures)
                {
                    picture.Compress(30);//压缩图片
                }
            }

            //保存文档
            wb.SaveToFile("CompressImgs.xlsx", ExcelVersion.Version2013);
            System.Diagnostics.Process.Start("CompressImgs.xlsx");
        }
    }
}
VB.NET
Imports Spire.Xls

Namespace CompressImgs
	Class Program
		Private Shared Sub Main(args As String())
			'加载Excel测试文档
			Dim wb As New Workbook()
			wb.LoadFromFile("test.xlsx")

			'遍历工作表
			For Each sheet As Worksheet In wb.Worksheets
				'遍历工作表中的所有图片
				For Each picture As ExcelPicture In sheet.Pictures
						'压缩图片
					picture.Compress(30)
				Next
			Next

			'保存文档
			wb.SaveToFile("CompressImgs.xlsx", ExcelVersion.Version2013)
			System.Diagnostics.Process.Start("CompressImgs.xlsx")
		End Sub
	End Class
End Namespace

压缩结果:

C#/VB.NET 压缩 Excel 中的图片

本文介绍如何使用Spire.Presentation for Java将ZIP文件嵌入PowerPoint文档中。

import com.spire.presentation.*;
import com.spire.presentation.drawing.IImageData;

import javax.imageio.ImageIO;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

public class InsertZip {

    public static void main(String[] args) throws Exception {

        //创建Presentation对象
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //获取第一个幻灯片
        ISlide slide = presentation.getSlides().get(0);

        //加载一个zip文件并转换为byte[]对象
        String filePath = "C:\\Users\\Administrator\\Desktop\\sample.zip";
        File zipFile = new File(filePath);
        FileInputStream inputStream = new FileInputStream(zipFile);
        byte[] data = new byte[(int) zipFile.length()];
        inputStream.read(data, 0, data.length);

        //加载一个图片作为zip文件的展示图片
        File file = new File("C:\\Users\\Administrator\\Desktop\\winrar-icon.png");
        BufferedImage image = ImageIO.read(file);
        IImageData oleImage = presentation.getImages().append(image);
        
        //将zip文件嵌入第一个幻灯片
        Rectangle2D rect = new Rectangle2D.Float(60, 60, image.getWidth(), image.getHeight());
        IOleObject oleObject = slide.getShapes().appendOleObject("zip", data, rect);
        oleObject.getSubstituteImagePictureFillFormat().getPicture().setEmbedImage(oleImage);
        oleObject.setProgId("Package");
        
        //保存文档
        presentation.saveToFile("output/InsertZip.pptx", FileFormat.PPTX_2013);
    }
}

Java 在 PowerPoint 文档中嵌入 ZIP 文件

当我们与同事协同编辑一份 Excel 文档时,常会遇到这样一种情况:若 Excel 文档数据存在问题,我们就需要对文档中各个部分或某些内容进行修改。通常我们就会用到修订功能。因为使用修订可以直观地跟踪到文档的修改情况,看出是哪位作者对文档进行了修改,以及修改的正确内容。如果对文档拥有完全权限,则可以接受或拒绝每个修订。在本文中,您将学习如何使用 Spire.XLS for Java 一次接受或拒绝所有修订。

安装 Spire.XLS for Java

首先,您需要在 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>

接受工作表中的修订

您可以使用 Workbook.hasTrackedChanegs() 方法来确定工作簿是否已修订。如果是,可以使用 Workbook.acceptAllTrackedchanges() 方法一次接受所有修订。以下是在 Excel 工作簿中接受修订的具体步骤:

  • Java
import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;

public class AcceptTrackedChanges {

    public static void main(String[] args) {

        //创建一个Workbook对象
        Workbook wb = new Workbook();

        //加载示例 Excel 文档
        wb.loadFromFile("test.xlsx");

        //确认工作簿是否已修订
        if (wb.hasTrackedChanges())
        {
            //接受修订
            wb.acceptAllTrackedChanges();
        }

        //保存文件
        wb.saveToFile("AcceptChanges.xlsx", FileFormat.Version2013);
    }
}

Java 接受或拒绝 Excel 中的修订

拒绝工作表中的修订

如果已确定修订存在于工作簿中,您可以使用 Workbook.rejectAllTrackedChanges() 方法拒绝工作表中的修订。以下是实现此目的的步骤:

  • Java
import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;

public class RejectTrackedChanges {

    public static void main(String[] args) {

        //创建一个Workbook对象
        Workbook wb = new Workbook();

        //加载示例 Excel 文档
        wb.loadFromFile("test.xlsx");

        //确认工作簿是否已修订
        if (wb.hasTrackedChanges())
        {
            //拒绝修订
            wb.rejectAllTrackedChanges();
        }

        //保存文件
        wb.saveToFile("RejectChanges.xlsx", FileFormat.Version2013);
    }
}

Java 接受或拒绝 Excel 中的修订

申请临时 License

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

Spire.XLS for Java 4.8.1已发布。本次更新增强了转换Excel到PDF的功能,并且还修复了添加HTML字串符时出现的问题。详情请阅读以下内容。

问题修复:


下载Spire.XLS for Java 4.8.1请点击:

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

本文将介绍如何使用Spire.XLS for .NET转换Excel中的形状和SmartArt图形到图片。

原Excel文档:

C#/VB.NET 转换 Excel 中的形状和 SmartArt 图形到图片

C#
using Spire.Xls;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;

namespace Convert_Shapes_and_SmartArt_to_Image
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建Workbook对象
            Workbook workbook = new Workbook();
            //加载Excel文档
            workbook.LoadFromFile("Sample.xlsx");

            //获取第一个工作表
            Worksheet sheet = workbook.Worksheets[0];

            //创建SaveShapeTypeOption对象
            SaveShapeTypeOption shapelist = new SaveShapeTypeOption();
            //保存工作表中的形状和SmartArt图形到图片
            List<Bitmap> images = sheet.SaveShapesToImage(shapelist);

            //保存图片到指定路径
            int index = 0;
            foreach (Image img in images)
            {
                img.Save("Image/" + "toImage" + index + ".Png", ImageFormat.Png);
                index++;
            }
        }
    }
}
VB.NET
Imports Spire.Xls
Imports System.Collections.Generic
Imports System.Drawing.Imaging

Namespace Convert_Shapes_and_SmartArt_to_Image
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            '创建Workbook对象
            Dim workbook As Workbook = New Workbook()
            '加载Excel文档
            workbook.LoadFromFile("Sample.xlsx")

            '获取第一个工作表
            Dim sheet As Worksheet = workbook.Worksheets(0)

            '创建SaveShapeTypeOption对象
            Dim shapelist As SaveShapeTypeOption = New SaveShapeTypeOption()
            '保存工作表中的形状和SmartArt图形到图片
            Dim images As List(Of Bitmap) = sheet.SaveShapesToImage(shapelist)

            '保存图片到指定路径
            Dim index As Integer = 0

            For Each img As Image In images
                img.Save("Image/" & "toImage" & index & ".Png", ImageFormat.Png)
                index += 1
            Next
        End Sub
    End Class
End Namespace

转换结果:

C#/VB.NET 转换 Excel 中的形状和 SmartArt 图形到图片

项目符号和编号是放在文本前的点或其它符号,起强调作用。合理使用项目符号和编号,可以使文档的层次结构更清晰、更有条理。通过组织良好的列表,读者可以轻松了解每个项目的结构和要点。 本文将介绍如何使用 Spire.Doc for Java 从 Word 文档中的现有文本创建列表。

安装 Spire.Doc for Java

首先,您需要在 Java 程序中添加 Spire.Doc.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.doc</artifactId>
        <version>14.9.5</version>
    </dependency>
</dependencies>

从 Word 文档中的现有文本创建项目符号列表和编号列表

Spire.Doc for Java 提供了 ListFormat.applyBulletStyle() 和 ListFormat.applyNumberedStyle() 两种方法,用于创建项目符号和编号列表。

创建项目符号和编号列表的详细步骤如下:

  • Java
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.formatting.ListFormat;

public class CreateLists {
    public static void main(String[] args) {

        //创建 Document 类的对象
        Document document = new Document();

        //加载 Word 文档
        document.loadFromFile("测试文档.docx");

        //获取第一节
        Section section = document.getSections().get(0);

        //循环遍历第 4 到第 6 段
        for(int i = 3; i <= 5; i++){
            Paragraph para = section.getParagraphs().get(i);
            ListFormat listFormat = para.getListFormat();

            //应用项目符号列表样式
            listFormat.applyBulletStyle();

            //设置列表位置
            listFormat.getCurrentListLevel().setNumberPosition(-10);
        }

        //循环遍历第 8 到第 10 段
        for(int i = 7; i <= 9; i++){
            Paragraph para = section.getParagraphs().get(i);
            ListFormat listFormat = para.getListFormat();

            //应用编号列表样式
            listFormat.applyNumberedStyle();

            //设置列表位置
            listFormat.getCurrentListLevel().setNumberPosition(-10);

        }

        //保存文件
        document.saveToFile("创建列表.docx", FileFormat.Docx_2013);
    }
}

Java 从 Word 文档中的现有文本创建项目符号列表或编号列表

申请临时 License

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