Hi Team,
We are trying to delete the rows in an editable slide, where we need to delete the rows where we do not have data. For example, column 2022 has no data. We want tables to auto adjust based on data availability. We are using below Aspose version. I am not able to upload the ppt template - how to i share the sample template
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>23.3</version>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>23.3</version>
<classifier>javadoc</classifier>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>19.12</version>
<classifier>jdk16</classifier>
</dependency>
sample.7z (855.2 KB)
@natarajnb,
Thank you for contacting free support.
You can zip the file and upload an archive with the file here. Alternatively, you can share a link to the file saved in a file storage (Google Drive, Dropbox, etc).
Thanks @andrey.potapov : I have uploaded the sample editable ppt. Please help us on our requirement
@natarajnb,
Unfortunately, you were unable to upload the presentation file. Please try again.
Hi @andrey.potapov : I have uploaded a presentation inside a sample.7z file. Please let me know if you are able to find it
@natarajnb,
I see you attached a file to your first post. Thank you for the sample presentation. I need some time to check the issue. I will get back to you soon.
@natarajnb,
Thank you for your patience.
You are talking about deleting rows but you give a column as an example. Could you please clarify what exactly you want to delete and describe the expected result?
Hi @andrey.potapov : Thanks for your reply, when we remove the rows from the ppt work book the column in the ppt will get removed. I mean, the column in the ppt represent the row in the ppt workbook.
@natarajnb,
Thank you for the explanation. Unfortunately, I was unable to remove the row from the chart data using Aspose.Slides.
We have opened the following new ticket(s) in our internal issue tracking system and will consider your question according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESJAVA-39551
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@natarajnb,
Our developers have investigated the case. Since the specified operation in PowerPoint can be done only using Excel, we suggest using the following code snippet:
final Presentation presentation = new Presentation("sample.pptx");
try
{
ISlide slide = presentation.getSlides().get_Item(0);
for (IShape shape : slide.getShapes()) {
if (shape instanceof Chart) {
Chart chart = (Chart) shape;
byte[] workbookData = chart.getChartData().readWorkbookStream();
Workbook workbook = new Workbook(new ByteArrayInputStream(workbookData));
Worksheet worksheet = workbook.getWorksheets().get(0);
int endRow = worksheet.getCells().getMaxDataRow() + 1;
int endCol = worksheet.getCells().getMaxDataColumn();
int startColumn = 11;
int endColumn = 17;
int deletedRowCount = 0;
for (int rowIndex = worksheet.getCells().getMaxDataRow(); rowIndex >= 0; rowIndex--)
{
boolean isRowEmpty = true;
for (int colIndex = startColumn; colIndex <= endColumn; colIndex++)
{
Cell cell = worksheet.getCells().get(rowIndex, colIndex);
if (cell.getValue() != null && cell.getStringValue() != null && !cell.getStringValue().isEmpty())
{
isRowEmpty = false;
break;
}
}
if (isRowEmpty)
{
worksheet.getCells().deleteRow(rowIndex);
deletedRowCount++;
}
}
ArrayList colNames = new ArrayList();
for (int colIndex = 0; colIndex <= endCol; colIndex++)
{
Cell cell = worksheet.getCells().get(0, colIndex);
System.out.println(cell.getValue());
System.out.println(cell.getStringValue());
if (cell.getValue() == null)
{
endCol = cell.getColumn();
break;
}
else
{
if (colNames.contains(cell.getValue()))
{
endCol = cell.getColumn() - 1;
break;
}
colNames.add(cell.getValue());
}
}
endRow -= deletedRowCount;
Range updatedRange = worksheet.getCells().createRange(0, 0, endRow, endCol);
String newRange = updatedRange.getRefersTo().replace("=", "");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
workbook.save(baos, com.aspose.cells.SaveFormat.XLSX);
chart.getChartData().writeWorkbookStream(baos.toByteArray());
chart.getChartData().setRange(newRange);
}
}
presentation.save("output.pptx", SaveFormat.Pptx);
}
finally {
presentation.dispose();
}
The result: output.zip (855.8 KB)
Hi @andrey.potapov : Thanks for your code snippet, I will check it and get back to you in case i need more help or clarification.
@natarajnb,
Thank you for the message. We will be waiting for your feedback.
Hi @andrey.potapov : We are using aspose- slides 19.12 version and we are using below line to access the workbook
IChart chart = ((IChart) shapes.get_Item(Integer.parseInt(1));
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
Can you please provide the solution using Ichart and IchartDataWorkbook.
@natarajnb,
Unfortunately, the issue you described in the first post cannot be solved using only the IChartDataWorkbook
. The code example above works when you use Aspose.Slides with Aspose.Cells.
Hi @andrey.potapov : Thanks for your answer, We will check at our end to see how to fit the above code in our requirements since we are only using aspose slides library in our project
@natarajnb,
Thank you for the message. We will be waiting for your feedback.