Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用XSSF(Apache POI 3.8)调整图表的大小?_Java_Apache Poi - Fatal编程技术网

Java 如何使用XSSF(Apache POI 3.8)调整图表的大小?

Java 如何使用XSSF(Apache POI 3.8)调整图表的大小?,java,apache-poi,Java,Apache Poi,我想知道是否有一种方法可以使用ApachePOI(XSSF)调整图表的大小。目前我使用的是Excel模板,它有一个图表,当使用namedRanges插入更多数据时,图表会发生变化 一切正常,我面临的唯一问题是: 图表总是保持相同的大小,因此如果有更多的条目,它会变得杂乱无章,使图表变得毫无用处 我使用的是日期,但我无法在图表上以日/月(17/10)表示日期。基本上,它写的是36982,而不是2001年1月4日 工作簿的目的是列出几个作业,并检查它们在给定日期是否花费了更长的时间。图表有助于识

我想知道是否有一种方法可以使用ApachePOI(XSSF)调整图表的大小。目前我使用的是Excel模板,它有一个图表,当使用namedRanges插入更多数据时,图表会发生变化

一切正常,我面临的唯一问题是:

  • 图表总是保持相同的大小,因此如果有更多的条目,它会变得杂乱无章,使图表变得毫无用处
  • 我使用的是日期,但我无法在图表上以日/月(17/10)表示日期。基本上,它写的是36982,而不是2001年1月4日
工作簿的目的是列出几个作业,并检查它们在给定日期是否花费了更长的时间。图表有助于识别经过更长时间的情况。作业运行时的范围可能从秒到小时

这是我正在使用的代码:

package le_package.poi_tests.xssflibrary;
导入java.io.*;
导入java.text.simpleDataFormat;
导入java.util.Date;
导入org.apache.poi.openxml4j.opc.OPCPackage;
导入org.apache.poi.ss.usermodel.Cell;
导入org.apache.poi.ss.usermodel.Name;
导入org.apache.poi.ss.usermodel.Row;
导入org.apache.poi.ss.usermodel.Sheet;
导入org.apache.poi.xssf.usermodel.xssf工作簿;
公共类poreadfile{
公共静态void main(字符串[]args){
尝试
{           
String jobName=“我是一份工作”;
String jobParent=“我是你的父亲,Job。”;
int rowNum=40;
污损=4;
//以OOXML形式打开Excel
XSSFWorkbook currentWorkbook=新XSSFWorkbook(OPCPackage.open(“include/excelTemplate.xlsx”);
//将工作表置于位置0
Sheet currentSheet=currentWorkbook.getSheetAt(0);
//获取要处理的图纸名称
String sheetName=currentSheet.getSheetName();
//设置标题的值
currentSheet.getRow(1).getCell(0).setCellValue(jobName);
currentSheet.getRow(1).getCell(1).setCellValue(jobParent);
对于(int i=0;i
  • 给出你的日期单元格,日期格式。

  • POI无法修改图形AFAIK


  • 在研究了xlsx的工作原理之后,我找到了如何完成它的方法

    //Call the partiarch to start drawing
    XSSFDrawing drawing = ((XSSFSheet)currentSheet).createDrawingPatriarch();
    //Create CTMarket for anchor
    CTMarker chartEndCoords = CTMarker.Factory.newInstance();
    //The coordinates are set in columns and rows, not pixels.
    chartEndCoords.setCol(column);
    //Set Column offset
    chartEndCoords.setColOff(0);
    chartEndCoords.setRow(row);
    chartEndCoords.setRowOff(0);
    //drawing.getCTDrawing().getTwoCellAnchorArray(0).setFrom(chartStartCoords);
    drawing.getCTDrawing().getTwoCellAnchorArray(0).setTo(chartEndCoords);
    
    /*
        This line of code allows to resize the chart:
            The Patriarch is what allows to get control over the drawings, since
            a chart is considered a graph in xlsx you can access it with getCTDrawing.
            Each graph is stored in the tag getTwoCellAnchorArray, where the array position
            is the chart you have; for example getTwoCellAnchorArray(3) would refer to the
            forth graph within the sheet.
    
            Each getTwoCellAnchorArray has several properties as FROM and TO, which define
            where the existing graph starts and ends.   
    */
    

    如果您有任何意见,请告诉我。

    POI比HSSF更好地支持XSSF中的图形/图形,因为格式不太不透明。这就是说,今年夏天GSOC的一名学生添加了相当多的HSSF图形支持,所以最近情况好多了!您能分享一下您用来解决这个问题的资源吗?
    //Call the partiarch to start drawing
    XSSFDrawing drawing = ((XSSFSheet)currentSheet).createDrawingPatriarch();
    //Create CTMarket for anchor
    CTMarker chartEndCoords = CTMarker.Factory.newInstance();
    //The coordinates are set in columns and rows, not pixels.
    chartEndCoords.setCol(column);
    //Set Column offset
    chartEndCoords.setColOff(0);
    chartEndCoords.setRow(row);
    chartEndCoords.setRowOff(0);
    //drawing.getCTDrawing().getTwoCellAnchorArray(0).setFrom(chartStartCoords);
    drawing.getCTDrawing().getTwoCellAnchorArray(0).setTo(chartEndCoords);
    
    /*
        This line of code allows to resize the chart:
            The Patriarch is what allows to get control over the drawings, since
            a chart is considered a graph in xlsx you can access it with getCTDrawing.
            Each graph is stored in the tag getTwoCellAnchorArray, where the array position
            is the chart you have; for example getTwoCellAnchorArray(3) would refer to the
            forth graph within the sheet.
    
            Each getTwoCellAnchorArray has several properties as FROM and TO, which define
            where the existing graph starts and ends.   
    */