Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code to create chart without reading template file in PPT, Test Example file for DOC and PPT #135

Closed
wants to merge 18 commits into from

Conversation

sandeeptiwari32
Copy link

added code to create chart without reading template file in PPT and Test Example file for DOC and PPT

@@ -81,6 +82,27 @@

@Beta
public abstract class XDDFChart extends POIXMLDocumentPart implements TextContainer {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved constant variable code from XWPFChart TO XDDFChart

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the moved constants, we can't delete them from XWPFChart as it would cause issues for other users but could you set the XWPFChart values to be be based on the XDDF ones?

public static final int DEFAULT_WIDTH = XDDFChart.DEFAULT_WIDTH; 

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it...
merged required code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged required code.

@asfgit
Copy link

asfgit commented Nov 28, 2018

Can one of the admins verify this patch?

@@ -712,10 +734,29 @@ public CellReference setSheetTitle(String title, int column) {
XSSFRow row = this.getRow(sheet, 0);
XSSFCell cell = this.getCell(row, column);
cell.setCellValue(title);
this.updateSheetTable(sheet.getTables().get(0).getCTTable(), title, column);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sheet does't have table object then first create it and then pass newly created table to update sheet table data. so for that purpose created a method GetSheetTable to return table object.

return new CellReference(sheet.getSheetName(), 0, column, true, true);
}

/**
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method which check whether sheet have table object, in case table size is 0 then create table and return that table.

@@ -729,9 +770,11 @@ public CellReference setSheetTitle(String title, int column) {
private void updateSheetTable(CTTable ctTable, String title, int index) {
CTTableColumns tableColumnList = ctTable.getTableColumns();
CTTableColumn column = null;
for( int i = 0; tableColumnList.getCount() < index; i++) {
int columnCount = tableColumnList.getTableColumnList().size()-1;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of starting loop form 0 each time start it with table column size. previously each time we are adding new column from 0 inseatd from required index.

return chart;
}

/**
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a method to create template for chart as we have method for XWPFDocument and XSSFWorkbook.

@@ -416,7 +425,7 @@ public XSLFNotesMaster getNotesMaster() {
* Return all the charts in the slideshow
*/
public List<XSLFChart> getCharts() {
return _charts;
return Collections.unmodifiableList(_charts);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to unmodifiable list as we have unmodifiable list in XWPFDocument and XSSFWorkbook.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you Alain Sir... :)

@@ -90,4 +104,46 @@ protected CTTextBody getTextBody(boolean create) {
};
}
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method to create graphic frame for chart object in XSLFSLIDE

@@ -106,6 +106,18 @@ public XSLFTable createTable(){
shape.setAnchor(new Rectangle2D.Double());
return shape;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method to add chart into graphic frame of slide

@@ -718,5 +720,32 @@ public XSLFPlaceholderDetails getPlaceholderDetails(Placeholder placeholder) {
final XSLFSimpleShape ph = getPlaceholder(placeholder);
return (ph == null) ? null : new XSLFPlaceholderDetails(ph);
}

/**
* this method will add chart into slide
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method to add chart into slide with default height width and co-ordinate.

return addChart(chart, rect2D);
}

/**
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method to add chart into slide with user defined height width and co-ordinate.

*/
public static final int DEFAULT_HEIGHT = 500000;


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved code into XDDFChart class

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like already mentioned in other review, please refrain from deleting public code that other people might already be using in their production code.

Keep the definition of these constants as being = XDDFChart.DEFAULT_WIDTH and = XDDFChart.DEFAULT_HEIGHT

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged required code.

@@ -1672,7 +1673,7 @@ public XWPFDocument getXWPFDocument() {
* @since POI 4.0.0
*/
public XWPFChart createChart() throws InvalidFormatException, IOException {
return createChart(XWPFChart.DEFAULT_WIDTH, XWPFChart.DEFAULT_HEIGHT);
return createChart(XDDFChart.DEFAULT_WIDTH, XDDFChart.DEFAULT_HEIGHT);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed constant class name

@@ -194,4 +195,16 @@ public void testMergeSlides() throws IOException {

ppt.close();
}

@Test
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

junit test case for new method in XMLSlideShow "createChart"

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code to create chart without reading template file for PPT

@sandeeptiwari32
Copy link
Author

code to create chart without reading template file for PPT

column = tableColumnList.addNewTableColumn();
column.setId(i);
++columnCount;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use this?

for (int i = columnCount; i < index; i++) {
    column = tableColumnList.addNewTableColumn();
    column.setId(i);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad.. :P
done required change.

required to change loop condition to 'i' instead of  columnCount.
Copy link
Contributor

@Alain-Bearez Alain-Bearez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am so glad to see such a useful contribution complementing my original use case!

Double[] values2 = listSpeakers.toArray(new Double[listSpeakers.size()]);

try (XWPFDocument doc = new XWPFDocument()) {
XWPFChart chart = doc.createChart(5000000,5000000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use XDDFChart.DEFAULT_WIDTH and XDDFChart.DEFAULT_HEIGHT instead of these magic numbers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chnaged hard coded value to constant.

XSLFSlide slide = ppt.createSlide();
XSLFChart chart = ppt.createChart();
Rectangle2D rect2D = new java.awt.Rectangle(XDDFChart.DEFAULT_X, XDDFChart.DEFAULT_Y,
5000000, 5000000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use XDDFChart.DEFAULT_WIDTH and XDDFChart.DEFAULT_HEIGHT instead of these magic numbers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chnaged hard coded value to constant

/**
* This method is used to create template for chart XML.
* @return Xslf chart object
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the @since 4.0.2 as we might not be able to ship it with currently reviewed 4.0.1 to be released after the week-end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Tag POI 4.0.2

chart.setChartIndex(chartIdx);
_charts.add(chart);
return chart;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no trailing whitespaces, please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed space.

@@ -416,7 +425,7 @@ public XSLFNotesMaster getNotesMaster() {
* Return all the charts in the slideshow
*/
public List<XSLFChart> getCharts() {
return _charts;
return Collections.unmodifiableList(_charts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch!

* @param anchor size and location of chart
* @return graphic frame object
*/
static CTGraphicalObjectFrame prototype(int shapeId, String rID, Rectangle2D anchor){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need to be of package visibility? Wouldn't private be OK?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using this method from XSLF drawing as we are using for other shap controls. so need protected or package visibility.

*
* @param rID relation id of chart
* @param rect2D Chart Bounding values
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the @since 4.0.2 as we might not be able to ship it with currently reviewed 4.0.1 to be released after the week-end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Tag POI 4.0.2

* with default height, width, x and y
* @param chart xslf chart object
* @return xslf chart object
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the @since 4.0.2 as we might not be able to ship it with currently reviewed 4.0.1 to be released after the week-end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Tag POI 4.0.2

*/
public static final int DEFAULT_HEIGHT = 500000;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like already mentioned in other review, please refrain from deleting public code that other people might already be using in their production code.

Keep the definition of these constants as being = XDDFChart.DEFAULT_WIDTH and = XDDFChart.DEFAULT_HEIGHT

XSLFChart chart = ppt.createChart();
slide.addChart(chart);

assertNotNull(chart);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have checked that the returned chart from slide.addChart is the one you expect to be, i.e. the original chart passed as argument.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed method slide.addChart return type. no need to return XSLFchart object. we are using XSLFChart object to add relationship into slide.

instead of hard coded value changed it to constant.
instead of hard coded value changed it to constant
merged required changes
added since POI 4.0.2 tag
Added POI 4.0.2 Tag
removed trailing space
changed visibility CHART_URI constant and Added POI 4.0.2 Tag
Added POI 4.0.2 Tag
Added POI 4.0.2 Tag
updated test cases.
changed method, no required to return XLSFChart object.
@sandeeptiwari32
Copy link
Author

added required changes.

updated method comment
Copy link
Contributor

@Alain-Bearez Alain-Bearez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 more details

* in case table size zero then create new table and add table columns element
* @param sheet
* @return table object
* @since POI 4.0.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for @since tags on private methods.

@@ -36,16 +36,16 @@ Licensed to the Apache Software Foundation (ASF) under one or more
*/
@Beta
public class XWPFChart extends XDDFChart {
/**
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change in indentation here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be appeared because i edited it github web portal.
managed indentation.

public static final int DEFAULT_HEIGHT = 500000;

public static final int DEFAULT_HEIGHT = XDDFChart.DEFAULT_HEIGHT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no trailing whitespace, please!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be appeared because i edited it github web portal.
removed space.

changed indentation
changed indentation.
removed since tag
* this method will check whether sheet have table
* in case table size zero then create new table and add table columns element
* @param sheet
* @return table object
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed since tag

@@ -39,12 +39,12 @@ Licensed to the Apache Software Foundation (ASF) under one or more
/**
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be appeared because i edited it github web portal.
managed indentation.


/**
* default height of chart in emu
*/
public static final int DEFAULT_HEIGHT = 500000;
public static final int DEFAULT_HEIGHT = XDDFChart.DEFAULT_HEIGHT;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be appeared because i edited it github web portal.
removed space.

@sandeeptiwari32
Copy link
Author

updated required changes.

@pjfanning
Copy link
Contributor

@Alain-Bearez POI 4.0.1 is released. Do you think it is ok to merge this now?

@sandeeptiwari32
Copy link
Author

sandeeptiwari32 commented Dec 7, 2018

@Alain-Bearez is it ok to merge current changes, or still need to change something.

@Alain-Bearez
Copy link
Contributor

I am still fixing some formatting minor issues before merging.

@Alain-Bearez
Copy link
Contributor

merged by r1848432

@Alain-Bearez
Copy link
Contributor

@pjfanning how could we make sure all the required new CT* classes on
https://github.com/apache/poi/pull/135/files#diff-e7bf6663c76af8916ed221806ed98fa0
are present in the ooxml-lite?

Only then you could close this PR.

@pjfanning
Copy link
Contributor

@sandeeptiwari32 can you close the PR? I ran a quick check and it looks like we have all the XMLBeans generated classes that we need in poi-ooxml-schemas jar. That jar is a subset of the full ooxml-schemas.jar and the classes in subset are derived from the classes that are used in our unit tests.

@sandeeptiwari32
Copy link
Author

@pjfanning sure.

@sandeeptiwari32
Copy link
Author

close pull request.

@18876293672
Copy link

.......................................................................................

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants