找回密码
 立即注册

QQ登录

只需一步,快速开始

zhvczw

中级会员

65

主题

193

帖子

612

积分

中级会员

积分
612
zhvczw
中级会员   /  发表于:2021-1-21 18:01  /   查看:1979  /  回复:8
为什么引用数据透视表的工式显示错误?
image.png793014831.png
image.png212241820.png 下面是代码:

package com.wczw;

import com.grapecity.documents.excel.DeserializationOptions;
import com.grapecity.documents.excel.IWorksheet;
import com.grapecity.documents.excel.PdfSaveOptions;
import com.grapecity.documents.excel.Workbook;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class JsonToExcelTest03 {

    private static final Log log = LogFactory.getLog(JsonToExcelTest03.class);

    private static SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");


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

        // 测试目录
        File folder = new File("test");

        // 输入文件
        File excelIn = new File(folder, "简单Demo透视表和VLOOKUP.xlsx");

        // 输出文件PDF
        File pdf1 = new File(folder, "简单Demo透视表和VLOOKUP-out1.pdf");
        File pdf2 = new File(folder, "简单Demo透视表和VLOOKUP-out2.pdf");

//        // 输出文件Excel
        File excelOut = new File(folder, "简单Demo透视表和VLOOKUP-out.xlsx");

        Date startTime = new Date();



        // 初始化Excel对象
        Workbook workbook = new Workbook();

        DeserializationOptions deserializationOptions = new DeserializationOptions();
//        workbook.fromJson(json, deserializationOptions);
        workbook.open(excelIn.getAbsolutePath());








        // 修改数据
        IWorksheet worksheet = workbook.getWorksheets().get(0);
        int startLine = 2;
        int endLine = 45;
        Object[] o = new Object[endLine-startLine+1];
        for (int i=0; i< o.length; i++) {
            o = 558;
        }
        worksheet.getRange(String.format("D%d%d", startLine, endLine)).setValue(o);
        worksheet = workbook.getWorksheets().get(1);
        worksheet.getPivotTables().get(0).refresh();



        // 导出为Excel
        workbook.save(excelOut.getAbsolutePath());

        // 导出为PDF
        {
            PdfSaveOptions options = new PdfSaveOptions();

            worksheet = workbook.getWorksheets().get(1);
            worksheet.save(pdf1.getAbsolutePath());
            worksheet = workbook.getWorksheets().get(2);
            worksheet.save(pdf2.getAbsolutePath());
        }









        Date endTime = new Date();

        log.info(String.format("运行时间:%s -> %s,耗时:%d ", sdf.format(startTime), sdf.format(endTime), (endTime.getTime() - startTime.getTime())/1000 ));

    }
}











下面是POM:<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>gcexceltest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.grapecity.documents</groupId>
            <artifactId>gcexcel</artifactId>
            <version>4.0.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.ant/ant -->
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.10.9</version>
        </dependency>

    </dependencies>

</project>


附件是测试用Excel


多谢!

简单Demo透视表和VLOOKUP.zip

15.78 KB, 下载次数: 44

8 个回复

倒序浏览
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-1-21 18:31:14
沙发
问题收到,这边需要调研一下,预计明天给您回复。
回复 使用道具 举报
zhvczw
中级会员   /  发表于:2021-1-22 08:55:14
板凳
能否中午前答复
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-1-22 11:15:53
地板
zhvczw 发表于 2021-1-22 08:55
能否中午前答复

您好,麻烦您把demo的完整工程打包上传至论坛,这边调研一下。
回复 使用道具 举报
zhvczw
中级会员   /  发表于:2021-1-22 12:11:22
5#
工程上传了。

gcexceltest - 副本.zip

125.4 KB, 下载次数: 37

回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-1-22 12:28:47
6#

这边问题已经复现了,需要做进一步调研,此贴为您改为保留处理,有进展会在本帖更新。
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-1-22 13:48:44
7#
经调研,目前GCExcel暂不支持GETPIVOTDATA这个公式。
回复 使用道具 举报
zhvczw
中级会员   /  发表于:2021-1-22 16:18:30
8#
有版本计划吗?何时可以支持?
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-1-22 16:25:59
9#
zhvczw 发表于 2021-1-22 16:18
有版本计划吗?何时可以支持?

目前暂无计划,这边提一个需求,由研发做进一步评估
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部