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

Spire.Cloud 纯前端文档控件

Spire.PDF for Java 3.10.5已发布。该版本优化了转换PDF到图片的转换时间和加文本水印到PDF的时间,支持获取PDF水印和插入SVG到PDF的功能,以及修复了PDF转化到Word/Image时出现的问题。详情请阅读以下内容:

优化:

新功能:

问题修复:


获取Spire.PDF for Java 3.10.5,请点击:

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

数据透视图是 Excel 中强大的数据分析工具,可以帮助用户迅速总结、分析和展示大量数据。通过数据透视图,用户可以灵活地组织和汇总数据,识别趋势和模式,做出更有效的决策。本文将介绍如何使用 Spire.XLS for Java 和 Java 在 Excel 中创建数据透视图。

安装 Spire.XLS for Java

首先,您需要在 Java 程序中添加 Spire.XLS for Java 文件作为依赖项。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>

Java 在 Excel 中创建数据透视图

Spire.XLS for Java 提供了 Worksheet.getCharts().add(ExcelChartType pivotChartType, IPivotTable pivotTable) 方法,支持基于 Excel 中的特定数据透视表创建数据透视图。详细步骤如下:

  • C#
import com.spire.xls.*;
import com.spire.xls.core.IPivotTable;

public class CreatePivotChart {
    public static void main(String[] args) {
        // 创建 Workbook 对象
        Workbook workbook = new Workbook();
        // 加载 Excel 文件
        workbook.loadFromFile("示例.xlsx");

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

        // 获取工作表中的第一个数据透视表
        IPivotTable pivotTable = sheet.getPivotTables().get(0);

        // 基于数据透视表创建数据透视图
        Chart pivotChart = sheet.getCharts().add(ExcelChartType.ColumnClustered, pivotTable);

        // 设置图表位置
        pivotChart.setTopRow(1);
        pivotChart.setLeftColumn(11);
        pivotChart.setRightColumn(20);
        pivotChart.setBottomRow(15);

        // 将图表标题设置为 null
        pivotChart.setChartTitle("");

        // 保存生成的文件
        workbook.saveToFile("创建数据透视图.xlsx", ExcelVersion.Version2013);
        workbook.dispose();
    }
}

Java 在 Excel 中创建数据透视图

Java 显示或隐藏 Excel 数据透视图的字段按钮

你可以使用 Spire.XLS for Java 在数据透视图中显示或隐藏以下字段按钮:

详细步骤如下:

  • C#
import com.spire.xls.*;
import com.spire.xls.core.IPivotTable;

public class ShowOrHideFieldButtons {
    public static void main(String[] args) {
        // 创建 Workbook 对象
        Workbook workbook = new Workbook();
        // 加载 Excel 文件
        workbook.loadFromFile("示例.xlsx");

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

        // 获取工作表中的第一个数据透视表
        IPivotTable pivotTable = sheet.getPivotTables().get(0);

        // 基于数据透视表创建数据透视图
        Chart pivotChart = sheet.getCharts().add(ExcelChartType.ColumnClustered, pivotTable);

        // 设置图表位置
        pivotChart.setTopRow(1);
        pivotChart.setLeftColumn(11);
        pivotChart.setRightColumn(20);
        pivotChart.setBottomRow(15);

        // 将图表标题设置为 null
        pivotChart.setChartTitle("");

        // 隐藏特定字段按钮
        pivotChart.setDisplayAxisFieldButtons(false);
        pivotChart.setDisplayValueFieldButtons(false);
        // pivotChart.setDisplayLegendFieldButtons(false);
        // pivotChart.setShowReportFilterFieldButtons(false);
        // pivotChart.setDisplayEntireFieldButtons(false);

        // 保存生成的文件
        workbook.saveToFile("隐藏字段按钮.xlsx", ExcelVersion.Version2013);
        workbook.dispose();
    }
}

Java 显示或隐藏 Excel 数据透视图的字段按钮

Java 给 Excel 数据透视图系列设置格式

当使用 Spire.XLS for Java 基于数据透视表生成数据透视图时,数据透视图的系列不会自动创建。你需要向数据透视图添加系列,然后再应用所需的格式。详细步骤如下:

  • C#
import com.spire.xls.*;
import com.spire.xls.charts.ChartSerie;
import com.spire.xls.core.IPivotTable;

public class FormatChartSeries {
    public static void main(String[] args) {
        // 创建 Workbook 对象
        Workbook workbook = new Workbook();
        // 加载 Excel 文件
        workbook.loadFromFile("示例.xlsx");

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

        // 获取工作表中的第一个数据透视表
        IPivotTable pivotTable = sheet.getPivotTables().get(0);

        // 基于数据透视表创建数据透视图
        Chart pivotChart = sheet.getCharts().add(ExcelChartType.ColumnClustered, pivotTable);

        // 设置图表位置
        pivotChart.setTopRow(1);
        pivotChart.setLeftColumn(11);
        pivotChart.setRightColumn(20);
        pivotChart.setBottomRow(15);

        // 将图表标题设置为 null
        pivotChart.setChartTitle("");

        // 添加图表系列
        ChartSerie series = pivotChart.getSeries().add(ExcelChartType.ColumnClustered);

        // 设置数据条的宽度
        series.getCommonSerieFormat().setGapWidth(10);
        // series.getCommonSerieFormat().setOverlap(100);

        // 保存生成的文件
        workbook.saveToFile("设置数据透视图系列格式.xlsx", ExcelVersion.Version2013);
        workbook.dispose();
    }
}

Java 给 Excel 数据透视图系列设置格式

申请临时 License

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

前面我们介绍了如何使用Spire.XLS 创建散点图表,该文将介绍如何使用C#、VB.NET创建Excel气泡图表。

C#
using Spire.Xls;

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

        {
            //创建工作簿
            Workbook workbook = new Workbook();

            //添加工作表并设置名称 
            workbook.CreateEmptySheets(1);
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Name = "Sample";

            //创建气泡图表
            Chart chart = sheet.Charts.Add(ExcelChartType.Bubble);


            //指定图表所在位置
            chart.LeftColumn = 1;
            chart.RightColumn = 10;
            chart.TopRow = 1;
            chart.BottomRow = 20;

            //设置图表的名称和数据
            Spire.Xls.Charts.ChartSerie cs1 = chart.Series.Add("气泡图表");
            cs1.EnteredDirectlyValues = new object[] { 2.2, 5.6 };
            cs1.EnteredDirectlyCategoryLabels = new object[] { 1.1, 4.4 };
            cs1.EnteredDirectlyBubbles = new object[] { 3, 6 };

            //文档保存
            workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2010);
        }
    }
    
}
VB.NET
Imports Spire.Xls

Namespace BubbleChart
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            '创建工作簿
            Dim workbook As Workbook = New Workbook
            '添加工作表并设置名称
            workbook.CreateEmptySheets(1)
            Dim sheet As Worksheet = workbook.Worksheets(0)
            sheet.Name = "Chart data"
            '创建气泡图表 
            Dim chart As Chart = sheet.Charts.Add(ExcelChartType.Bubble)
            '指定图表所在位置 
            chart.LeftColumn = 1
            chart.RightColumn = 10
            chart.TopRow = 1
            chart.BottomRow = 20
            '设置图表的名称和数据 
            Dim cs1 As Spire.Xls.Charts.ChartSerie = chart.Series.Add("气泡图表")
            cs1.EnteredDirectlyValues = New Object() {2.2, 5.6}
            cs1.EnteredDirectlyCategoryLabels = New Object() {1.1, 4.4}
            cs1.EnteredDirectlyBubbles = New Object() {3, 6}
            '文档保存 
            workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2010)
        End Sub
    End Class
End Namespace

气泡图表效果图:

C#/VB.NET 在 Excel 中创建气泡图表

Spire.Spreadsheet 4.10.1现已发布。该版本主要修复了公式计算不正确的问题。详情如下。

问题修复:


获取Spire.Spreadsheet 4.10.1,请点击:

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

Spire.PDF 6.10.4已发布。该版本调整转换到PDF/A文档接口为Spire.Pdf.Conversion, 同时新增了转换PDF到PDF/A3A, PDF/A3B以及创建值为空的自定义属性的功能,以及修复了PDF转换到Image/XPS/PCL时出现的问题。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.PDF 6.10.4,请点击:

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

本文介绍如何使用Spire.Presentation for Java在PowerPoint文档中插入折线图。

import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
import com.spire.presentation.charts.ChartLegendPositionType;
import com.spire.presentation.charts.ChartType;
import com.spire.presentation.charts.IChart;

import java.awt.geom.Rectangle2D;

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

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

        //插入折线图
        Rectangle2D.Double rect = new   Rectangle2D.Double(100, 50, 600, 430);
        IChart chart = presentation.getSlides().get(0).getShapes().appendChart(ChartType.LINE, rect);

        //设置图表标题
        chart.getChartTitle().getTextProperties().setText("产品月销量趋势");
        chart.getChartTitle().getTextProperties().isCentered(true);
        chart.getChartTitle().setHeight(30);
        chart.hasTitle(true);

        //设置轴标题
        chart.getPrimaryCategoryAxis().getTitle().getTextProperties().setText("月份");
        chart.getPrimaryCategoryAxis().hasTitle(true);
        chart.getPrimaryValueAxis().getTitle().getTextProperties().setText("销量");
        chart.getPrimaryValueAxis().hasTitle(true);

        //写入图表数据
        chart.getChartData().get(0,0).setText("月份");
        chart.getChartData().get(1,0).setText("一月");
        chart.getChartData().get(2,0).setText("二月");
        chart.getChartData().get(3,0).setText("三月");
        chart.getChartData().get(4,0).setText("四月");
        chart.getChartData().get(5,0).setText("五月");
        chart.getChartData().get(6,0).setText("六月");

        chart.getChartData().get(0,1).setText("台式机");
        chart.getChartData().get(1,1).setNumberValue(80);
        chart.getChartData().get(2,1).setNumberValue(45);
        chart.getChartData().get(3,1).setNumberValue(25);
        chart.getChartData().get(4,1).setNumberValue(20);
        chart.getChartData().get(5,1).setNumberValue(10);
        chart.getChartData().get(6,1).setNumberValue(5);

        chart.getChartData().get(0,2).setText("笔记本");
        chart.getChartData().get(1,2).setNumberValue(30);
        chart.getChartData().get(2,2).setNumberValue(25);
        chart.getChartData().get(3,2).setNumberValue(35);
        chart.getChartData().get(4,2).setNumberValue(50);
        chart.getChartData().get(5,2).setNumberValue(45);
        chart.getChartData().get(6,2).setNumberValue(55);

        chart.getChartData().get(0,3).setText("平板");
        chart.getChartData().get(1,3).setNumberValue(10);
        chart.getChartData().get(2,3).setNumberValue(15);
        chart.getChartData().get(3,3).setNumberValue(20);
        chart.getChartData().get(4,3).setNumberValue(35);
        chart.getChartData().get(5,3).setNumberValue(60);
        chart.getChartData().get(6,3).setNumberValue(95);

        //设置系列标签
        chart.getSeries().setSeriesLabel(chart.getChartData().get("B1", "D1"));

        //设置分类标签
        chart.getCategories().setCategoryLabels(chart.getChartData().get("A2", "A7"));

        //设置系列数据区域
        chart.getSeries().get(0).setValues(chart.getChartData().get("B2", "B7"));
        chart.getSeries().get(1).setValues(chart.getChartData().get("C2", "C7"));
        chart.getSeries().get(2).setValues(chart.getChartData().get("D2", "D7"));

        //在数据标签中显示数据
        chart.getSeries().get(0).getDataLabels().setLabelValueVisible(true);
        chart.getSeries().get(1).getDataLabels().setLabelValueVisible(true);
        chart.getSeries().get(2).getDataLabels().setLabelValueVisible(true);

        //设置图例位置
        chart.getChartLegend().setPosition(ChartLegendPositionType.TOP);

        //保存文档
        presentation.saveToFile("LineChart.pptx", FileFormat.PPTX_2013);
    }
}

Java 在 PowerPoint 中创建折线图

本文介绍使用Spire.PDF for .NET 将PDF转为Html的方法。将Html转为PDF可参考这篇文章。

C#
using Spire.Pdf;

namespace PDFtoHtml
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载PDF文档
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("sample.pdf");

            //调用方法将文件保存为html
            pdf.SaveToFile("ToHtml.html", FileFormat.HTML);
            System.Diagnostics.Process.Start("ToHtml.html");
        }
    }
}
VB.NET
Imports Spire.Pdf

Namespace PDFtoHtml
	Class Program
		Private Shared Sub Main(args As String())
			'加载PDF文档
			Dim pdf As New PdfDocument()
			pdf.LoadFromFile("sample.pdf")

			'调用方法将文件保存为html
			pdf.SaveToFile("ToHtml.html", FileFormat.HTML)
			System.Diagnostics.Process.Start("ToHtml.html")
		End Sub
	End Class
End Namespace

转换结果:

C#/VB.NET 将 PDF 转为 Html

Spire.XLS 10.10.6已发布。该版本新增了转换Excel到PDF A/1B和计算Office365文档中的XLOOKUP公式的功能,增强了Excel转化到PDF/HTML的性能并且修复了加载和保存Excel文档时出现的问题。详细请阅读以下内容。

新功能:

问题修复:


下载Spire.XLS 10.10.6,请点击:

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

前面我们介绍了如何使用Spire.Doc for Java 为Word文档添加文本水印和图片水印。当Word 文档中的某些部分,如段落,文本域Text Range, 表格,文本框和图形设置了背景色时,会出现水印被遮挡现象。该示例将详细介绍在Java应用程序中,给Word文档添加图片水印时移除段落,文本域,表格和文本框的背景色。

import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.*;

import java.awt.*;

public class WordWatermark {

    public static void main(String[] args) {
        //加载文档
        Document document = new Document("Sample.docx");
        //移除背景色
        SetNoFillForParagraphsAndTablesAndTextBoxes(document);
        //插入图片水印
        insertImageWatermark(document);
        //保存文档
        String output = "Result.docx";
        document.saveToFile(output, FileFormat.Docx);
    }
    public static void insertImageWatermark(Document document) {
        PictureWatermark picture = new PictureWatermark();
        picture.setPicture("logo.jpg");
        picture.setScaling(250);
        picture.isWashout(false);
        document.setWatermark(picture);
    }
    static void SetNoFillForParagraphsAndTablesAndTextBoxes(Document document) {
        Section section;
        Paragraph paragraph;
        TextRange textRange;
        for (int i = 0; i < document.getSections().getCount(); i++) {
            section = document.getSections().get(i);
            //移除段落中的背景色
            for (int j = 0; j < section.getBody().getParagraphs().getCount(); j++) {
                paragraph = section.getBody().getParagraphs().get(j);
                RemoveBackgroudColorOfParagraph(paragraph);
            }
            Table table;
            //移除表格中的背景色
            for (int t = 0; t < section.getBody().getTables().getCount(); t++) {
                table = section.getBody().getTables().get(t);
                table.getTableFormat().clearBackground();
                for(int r=0;r<table.getRows().getCount();r++){
                    TableRow row =table.getRows().get(r);
                    row.getRowFormat().clearBackground();
                    for(int c=0;c<row.getCells().getCount();c++){
                        TableCell cell = row.getCells().get(c);
                        cell.getCellFormat().clearBackground();
                        for(int p=0;p<cell.getParagraphs().getCount();p++) {
                            paragraph = (Paragraph) cell.getParagraphs().get(p);
                            //移除段落中的背景色
                            RemoveBackgroudColorOfParagraph(paragraph);
                        }
                    }
                }
            }
            //移除文本框中的背景色
            TextBox textBox;
            for (int n = 0; n < document.getTextBoxes().getCount(); n++) {
                document.getTextBoxes().get(n).getFormat().setFillColor(null);
                for(int t=0;t<document.getTextBoxes().getCount();t++) {
                    textBox = document.getTextBoxes().get(t);
                    for(int p=0;p<textBox.getChildObjects().getCount();p++)
                        if(textBox.getChildObjects().get(p) instanceof Paragraph) {
                            paragraph = (Paragraph) textBox.getChildObjects().get(p);
                            //移除段落中的背景色
                            RemoveBackgroudColorOfParagraph(paragraph);
                        }
                }
            }

        }
    }
    static void RemoveBackgroudColorOfParagraph(Paragraph paragraph)
    {
        TextRange textRange;
        paragraph.getFormat().setBackColor(new Color(0, 0, 0, 0));
        for (int k = 0; k < paragraph.getChildObjects().getCount(); k++) {
            if (paragraph.getChildObjects().get(k) instanceof TextRange) {
                textRange = (TextRange) paragraph.getChildObjects().get(k);
                //移除文本域中的背景色
                textRange.getCharacterFormat().setTextBackgroundColor(new Color(0, 0, 0, 0));
            }
        }
    }
}

效果图:

Java 添加 Word 水印时,移除段落、文本域、表格和文本框中的背景色

Spire. Office 5.10.0已正式发布。该版本主要修复了在操作PDF和Word文档时遇到的一些问题,例如:Spire.PDF加强了PDF转图片及打印功能;Spire.Doc增强了Word转PDF的功能,并且成功修复了一些在合并和保存文档后出现的问题。问题修复详情如下。

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

版本信息如下:

获取Spire.Office 5.10.0, 请点击:

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


Spire.PDF

问题修复:


Spire.Doc

问题修复: