Worksheets.SetOleSize in Java version

It was by mistake. Following is the correct code.

int xPos = 1000 / 2;

int yPos = 0;

int width =(int) pres.getSlideSize().getX() - 1000;

int height =(int) pres.getSlideSize().getY();

sld.getShapes().addOleObjectFrame(xPos, yPos, width, height, "Excel.Sheet.8", array);

Hi msfaiz,

Thanks for your response.

Below is the code am using to embed Excel in PPT , but the whole sheet is not coming under

single slide.If i hard code the set olesize

workbook.setOleSize(0, 50, 0, 70);

am getting the output as in screenshot jpg which you attached, how to dynamically set the OleSize .

public void cleanUpExcelFile(String sFileInput, String sFileOutput,

int headerVal, int footerVal) {

Workbook workbook = new Workbook();

try {

workbook.open(sFileInput);

Worksheets worksheets = workbook.getWorksheets();

Worksheet sheet = worksheets.getSheet(0);

for (int i = worksheets.size() - 1; i > 0; --i) {

worksheets.removeSheet(i);

}

workbook.save(sFileOutput);

} catch (Exception e) {

e.printStackTrace();

}

}

private void generatePPT(String sExcelFile, String sPPtTemplate,

String sPptOutput) {

try {

Presentation pres = new Presentation(new FileInputStream(

sPPtTemplate));

Slide slide1 = pres.getSlideByPosition(1);

File file = new File(sExcelFile);

int length = (int) file.length();

FileInputStream fstro = new FileInputStream(file);

byte[] b = new byte[length];

fstro.read(b, 0, length);

int xPos = 1000 / 2;

int yPos = 0;

int width =(int) pres.getSlideSize().getX() - 1000;

int height =(int) pres.getSlideSize().getY();

slide1.getShapes().addOleObjectFrame(xPos, yPos, width, height, "Excel.Sheet.8", b);

/*

OleObjectFrame oof = slide1.getShapes().addOleObjectFrame(150, 500,

(int) pres.getSlideSize().getX() - 200,

(int) pres.getSlideSize().getY() - 1500, "Excel.Sheet.8", b);

*/

FileOutputStream fos = new FileOutputStream(sPptOutput);

pres.write(fos);

fos.flush();

fos.close();

} catch (PptException e) {

System.out.println("PPT Exception" + e);

e.printStackTrace();

} catch (IOException e) {

System.out.println("IO Exception caught " + e);

e.printStackTrace();

}

}

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

System.out.println("Start");

String sInFile = "c:/Export2PPT/temp.xls";

String sOutfile = "C:/Export2PPT//temp_output.xls";

String sPPtTemplate = "C:/Export2PPT/demo.ppt";

String sPptOutput = "C:/Export2PPT/result.ppt";

Demo obj = new Demo();

obj.cleanUpExcelFile(sInFile, sOutfile, 2, 1);

obj.generatePPT(sOutfile, sPPtTemplate, sPptOutput);

System.out.println("End");

}

please let me know where am making the mistake.

Regards

Janakiraman

Helllo,

Which version of Aspose.Cells for JAVA you are using. I am getting error.

java.lang.ArrayIndexOutOfBoundsException

at java.lang.System.arraycopy(Native Method)

at com.aspose.cells.fr.a(Unknown Source)

at com.aspose.cells.cO.a(Unknown Source)

at com.aspose.cells.ec.a(Unknown Source)

at com.aspose.cells.ec.b(Unknown Source)

at com.aspose.cells.ec.a(Unknown Source)

at com.aspose.cells.Workbook.a(Unknown Source)

at com.aspose.cells.Workbook.a(Unknown Source)

at com.aspose.cells.Workbook.open(Unknown Source)

at clsPPTPractice.main(clsPPTPractice.java:28)

Hello Aspose.Cells team,

Please fix the above error. I have attached the source excel file. Below is the code. It is occuring in the latest version of Aspose.Cells for JAVA 2.0.1 JDK 5.0.

CODE:

Workbook wb = new Workbook();

wb.open("D:/downloads/source.xls");

Hi Shakeel,

Thank you for considering Aspose.

Please use the attached latest fix of Aspose.Cells for Java. The template file works fine with the attached fix.

Thank You & Best Regards,

Dear Janakiraman,

You are not doing anything wrong. Your excel file will not work. Actually, I created a new excel file which is attached namely source.xls by copying-pasting the contents from original downloadXls.xls

The sheet size including all the contents is M48.

It means

The columns spans from A-M i.e 0-12

The rows spans from 1-48 i.e 0-47

So, setolesize will take these parameters

wb.setOleSize(0, 47, 0, 12);

Below is the complete code which has been run using Aspose.Cells for JAVA 2.0.1.6 and Aspose.Slides for JAVA 1.9.

Its output namely output.ppt is also attached. If you double click it, the sheet will automatically fit to slide and displays all of its contents. This time, I set the Aspose.Cells license so that not to see the Evaluation Mark sheet on double clicking the OLE object.

CODE:

com.aspose.cells.License lic=new License();

lic.setLicense(new FileInputStream(“D:/Shakeel Projects/Aspose/License/new2/Aspose.Total.Java.lic”));

Presentation pres = new Presentation();

Slide sld = pres.getSlideByPosition(1);

int xPos = 1000 / 2;

int yPos = 0;

int width = (int )pres.getSlideSize().getX() - 1000;

int height= (int )pres.getSlideSize().getY();

Workbook wb = new Workbook();

wb.open(“D:/downloads/source.xls”);

wb.setOleSize(0, 47, 0, 12);

ByteArrayOutputStream bout=new ByteArrayOutputStream();

wb.save(bout);

OleObjectFrame oof= sld.getShapes().addOleObjectFrame(xPos, yPos, width, height, “Excel.Sheet.8”, bout.toByteArray());

pres.write(new FileOutputStream(“C:\output.ppt”));

Hi msfaiz ,

Thanks for your response.

I tried with your Excel file its working fine.

But the colors of the chart and table in the excel is totally different , when it is embedded in the PPT generated.

How to obtain the same colors in PPT as in Excel file.

Regards

Janakiraman

It seems to be a bug. We will fix it after further investigation. However, certain colors do not change. For example, red, blue, green, black etc. You can use those colors until we fix the problem.

Hi,

Thanks for your reply.

Once it is fixed please provide us the fixed version.

May i know the reason why my Xls file will not work as you have mentioned in issue id 174259 ,is it

resolvable or not.

Regards

Janakiraman

Hi,

Iam waiting for your response , please lets us know if there is any updates.

Regards

Janakiraman

Hello Janakiraman,

I don’t know for sure and I think, Aspose.Cells team can guide you better but apparently the difference between my soruce.xls and yours downloadXls.xls is that some of columns (e.g I) are wider than normal size in yours. That’s why setOleSize does not work as expected by me.

But as you already said in 174161, it works if you take columns up to 70

If i hard code the set olesize

workbook.setOleSize(0, 50, 0, 70);

Regarding coloring issue, once Aspose.Slides team will fix it, I will let you know.

Hello Nausherwan,

Please explain, what is generalized way of calculating the setOleSize parameters that should work for both soruce.xls and downloadXls attached at post id 174259

Currently, we have to hardcode.

For soruce.xls : wb.setOleSize(0, 47, 0, 12);

For downloadXls.xls: workbook.setOleSize(0, 50, 0, 70);

Hi msfaiz,

Thanks for your response.

Yeah if we hard code it looks good for that particular xls file , but we cant expect it to work for

all the Report Excels.

I will wait for Aspose Cells teams response over this.

Please update us on , regarding resolution issue rasied in the Post ID 173092 , when we change the

resolution of the system the object position is getting changed in the slide.

Please let me know , when can i expect the fixed version for coloring and resolution issue.

Regards

Janakiraman

Hi,

Thank you for considering Aspose.

Well, to generalize the maxRow and maxColumn for setOleSize, please consult the sample code I shared in the same thread from the following post link,

Thank You & Best Regards,

Hi,

Thanks for your response.

But the thing is , even if we set the max row and column for setOleSize , the embedded object in Slide is not coming under single slide view , files are attached in the post id 172680 .

Please let me know if you need more information.

Regards

Janakiraman

Hi

when can i expect the fixed version of coloring and resolution issue as metioned in issue ID : 174904

Regards

Janakiraman

Hi,

Thank you for considering Aspose.

We have tested your issue by using your template files (dowloadXls.xls and source.xls) with the latest version of Aspose.Cells (V2.0.1.6) and Aspose.Slides V1.9.1.0 and attached are the generated file (res_down.ppt) and the sample code. The embedded object can be shown correctly under single slide view. Please check it and let us know if it works fine for you.

Thank You & Best Regards,

Hi,

Thanks for your response.

But unfortunately it is not working for us .Have you used downloadxls.xls atached in the post id

174259. We used that file , but we are not getting the output as you are getting in res_down.ppt.

Regards

Janakiraman

hi,

Any updates on issue id : 175132

Regards

Janakiraman

Hi,

Thank you for considering Aspose.

Yes, we have used the same “downloadXls.xls” file to generate res_down.ppt. This issue is very strange, we have tested this issue on our side and it works fine but you are still not getting the right output. We are working with Aspose.Slides team to resolve this issue and we will let you know when we come to a solution as per your mentioned issue.

Thank you for understanding and helping us figure out the issue,

Hello,

The coloring issue is not because of Aspose.Slides.

After much investigation, I found that the fill color does not change if Excel file is inserted directly without using Aspose.Cells.

But if it is inserted after opening with Aspose.Cells, then fill color gets changed. I have developed the two test cases and requested the Aspose.Cells to fix the bug.

Please see the test cases here.

Aspose.Cells changing fill color of the cell

FYI:

Aspose.Slides does not manipulate the OLE contents. In fact, it does not even understand what is inside an OLE object. OLE is Microsoft technology to embed third-party documents.