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

@sandeeptiwari32 sandeeptiwari32 commented Nov 28, 2018

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

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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

Loading

Copy link
Contributor

@pjfanning pjfanning Nov 29, 2018

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; 

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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.

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

Choose a reason for hiding this comment

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

merged required code.

Loading

@asfgit
Copy link

@asfgit asfgit commented Nov 28, 2018

Can one of the admins verify this patch?

Loading

@@ -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

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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.

Loading

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

/**
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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.

Loading

@@ -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

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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.

Loading

return chart;
}

/**
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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.

Loading

@@ -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

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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.

Loading

Copy link
Contributor

@Alain-Bearez Alain-Bearez Nov 29, 2018

Choose a reason for hiding this comment

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

great catch!

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

Choose a reason for hiding this comment

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

thank you Alain Sir... :)

Loading

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

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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

Loading

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

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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

Loading

@@ -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

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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.

Loading

return addChart(chart, rect2D);
}

/**
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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.

Loading

*/
public static final int DEFAULT_HEIGHT = 500000;


Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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

Loading

Copy link
Contributor

@Alain-Bearez Alain-Bearez Nov 29, 2018

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

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

Choose a reason for hiding this comment

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

merged required code.

Loading

@@ -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

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

Choose a reason for hiding this comment

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

changed constant class name

Loading

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

ppt.close();
}

@Test
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 28, 2018

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"

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 left a comment

code to create chart without reading template file for PPT

Loading

@sandeeptiwari32
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 commented Nov 28, 2018

code to create chart without reading template file for PPT

Loading

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

@pjfanning pjfanning Nov 28, 2018

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);
}

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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.

Loading

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

@Alain-Bearez Alain-Bearez left a comment

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

Loading

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

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

@Alain-Bearez Alain-Bearez Nov 29, 2018

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.

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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.

Loading

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

@Alain-Bearez Alain-Bearez Nov 29, 2018

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.

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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

Loading

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

@Alain-Bearez Alain-Bearez Nov 29, 2018

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

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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

Loading

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

Copy link
Contributor

@Alain-Bearez Alain-Bearez Nov 29, 2018

Choose a reason for hiding this comment

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

no trailing whitespaces, please

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

Choose a reason for hiding this comment

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

removed space.

Loading

@@ -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

@Alain-Bearez Alain-Bearez Nov 29, 2018

Choose a reason for hiding this comment

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

great catch!

Loading

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

@Alain-Bearez Alain-Bearez Nov 29, 2018

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?

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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.

Loading

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

@Alain-Bearez Alain-Bearez Nov 29, 2018

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

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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

Loading

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

@Alain-Bearez Alain-Bearez Nov 29, 2018

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

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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

Loading

*/
public static final int DEFAULT_HEIGHT = 500000;


Copy link
Contributor

@Alain-Bearez Alain-Bearez Nov 29, 2018

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

Loading

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

assertNotNull(chart);
Copy link
Contributor

@Alain-Bearez Alain-Bearez Nov 29, 2018

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.

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Nov 29, 2018

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.

Loading

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

@sandeeptiwari32 sandeeptiwari32 commented Nov 29, 2018

added required changes.

Loading

updated method comment
Copy link
Contributor

@Alain-Bearez Alain-Bearez left a comment

3 more details

Loading

* 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

@Alain-Bearez Alain-Bearez Nov 30, 2018

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.

Loading

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

@Alain-Bearez Alain-Bearez Nov 30, 2018

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?

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Dec 1, 2018

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.

Loading

public static final int DEFAULT_HEIGHT = 500000;

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

@Alain-Bearez Alain-Bearez Nov 30, 2018

Choose a reason for hiding this comment

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

no trailing whitespace, please!

Loading

Copy link
Author

@sandeeptiwari32 sandeeptiwari32 Dec 1, 2018

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.

Loading

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

@sandeeptiwari32 sandeeptiwari32 Dec 1, 2018

Choose a reason for hiding this comment

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

removed since tag

Loading

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

@sandeeptiwari32 sandeeptiwari32 Dec 1, 2018

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.

Loading


/**
* 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

@sandeeptiwari32 sandeeptiwari32 Dec 1, 2018

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.

Loading

@sandeeptiwari32
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 commented Dec 1, 2018

updated required changes.

Loading

@pjfanning
Copy link
Contributor

@pjfanning pjfanning commented Dec 3, 2018

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

Loading

@sandeeptiwari32
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 commented Dec 7, 2018

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

Loading

@Alain-Bearez
Copy link
Contributor

@Alain-Bearez Alain-Bearez commented Dec 8, 2018

I am still fixing some formatting minor issues before merging.

Loading

@Alain-Bearez
Copy link
Contributor

@Alain-Bearez Alain-Bearez commented Dec 8, 2018

merged by r1848432

Loading

@Alain-Bearez
Copy link
Contributor

@Alain-Bearez Alain-Bearez commented Dec 8, 2018

@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.

Loading

@pjfanning
Copy link
Contributor

@pjfanning pjfanning commented Dec 8, 2018

@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.

Loading

@sandeeptiwari32
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 commented Dec 8, 2018

@pjfanning sure.

Loading

@sandeeptiwari32
Copy link
Author

@sandeeptiwari32 sandeeptiwari32 commented Dec 8, 2018

close pull request.

Loading

@18876293672
Copy link

@18876293672 18876293672 commented Sep 24, 2019

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

Loading

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