Page 1 of 1

Edit Microsoft Chart Data in pptx

PostPosted: Tue May 22, 2012 6:25 pm
by arahant7
I have an embedded Microsoft Chart in a pptx.
The relevant slide xml is:
Code: Select all
        <a:graphic>
          <a:graphicData uri="http://schemas.openxmlformats.org/presentationml/2006/ole">
            <p:oleObj spid="_x0000_s1902595" name="Chart" r:id="rId4" imgW="9324832" imgH="7153227" progId="MSGraph.Chart.8">
              <p:embed followColorScheme="full"/>
            </p:oleObj>
          </a:graphicData>
        </a:graphic>


The relationship rid4 is:
Code: Select all
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" Target="../embeddings/oleObject1.bin"/>


I want to know how to programmatically access the chart data in the .bin file and manipulate it.
Thanks

Re: Edit Microsoft Chart Data in pptx

PostPosted: Tue May 22, 2012 7:55 pm
by jason
Try running your pptx through the PartsList sample.

Hopefully it will tell you the embedded chart is an OleObjectBinaryPart.

That part contains methods initPOIFSFileSystem() and getFs(). Call them in that order. getFs() returns a POIFSFileSystem object (which you can Google).

Re: Edit Microsoft Chart Data in pptx

PostPosted: Wed May 23, 2012 4:32 am
by arahant7
Thanks. Yes I was able to figure that there was a OleObjectBinaryPart part.

However I still don't know how to locate the chart data. I tried this
Code: Select all
   
PartName bin1PartName = new PartName("/ppt/embeddings/oleObject1.bin");
OleObjectBinaryPart binaryPart = (OleObjectBinaryPart)parts.get(bin1PartName);
binaryPart.initPOIFSFileSystem();
      
POIFSFileSystem poiFsFileSystem = binaryPart.getFs();
HSSFWorkbook wb = new HSSFWorkbook(poiFsFileSystem);

Exception in thread "main" org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance
Caused by: org.apache.poi.hssf.record.RecordFormatException: Not enough data (0) to read requested (2) bytes


Not sure why this happens. The bin file seems not corrupted because the pptx opens and chart displays promptly.
Maybe it's the BIFF version? Is there some way to tell the BIFF version of the .bin file?
Other than the code above, there seems to be no way to read the data. If there is, please let me know.
Any help would be appreciated

Re: Edit Microsoft Chart Data in pptx

PostPosted: Wed May 23, 2012 8:55 am
by jason
what does viewFile(true) tell you?

Re: Edit Microsoft Chart Data in pptx

PostPosted: Wed May 23, 2012 3:04 pm
by arahant7
It shows me much of the bin file data. I'll post the entire file (after removing some binary data) here. Maybe the file is in some GBIFF5 format.


Root Entry -
CompObj <(0x01)CompObj> [101 / 0x65]
Workbook [3781 / 0xec5]
OlePres000 <(0x02)OlePres000> [8098 / 0x1fa2]
Ole <(0x01)Ole> [20 / 0x14]
POIFS FileSystem
Property: "Root Entry"
Name = "Root Entry"
Property Type = 5
Node Color = 1
Time 1 = 0
Time 2 = 0
CompObj
Property: "CompObj"
Name = "CompObj"
Property Type = 2
Node Color = 1
Time 1 = 0
Time 2 = 0
Document: "CompObj" size = 101
00000000 01 00 FE FF 03 0A 00 00 FF FF FF FF 03 08 02 00 ................
00000010 00 00 00 00 C0 00 00 00 00 00 00 46 16 00 00 00 ...........F....
00000020 4D 69 63 72 6F 73 6F 66 74 20 47 72 61 70 68 20 Microsoft Graph
00000030 43 68 61 72 74 00 07 00 00 00 47 42 69 66 66 35 Chart.....GBiff5
00000040 00 10 00 00 00 4D 53 47 72 61 70 68 2E 43 68 61 .....MSGraph.Cha
00000050 72 74 2E 38 00 F4 39 B2 71 00 00 00 00 00 00 00 rt.8..9.q.......
00000060 00 00 00 00 00 .....
Workbook
Property: "Workbook"
Name = "Workbook"
Property Type = 2
Node Color = 1
Time 1 = 0
Time 2 = 0
Document: "Workbook" size = 3781
00000000 09 08 10 00 80 06 05 00 A9 1F CD 07 C1 00 01 00 ................
00000010 06 04 00 00 42 00 02 00 B0 04 22 00 02 00 00 00 ....B.....".....
00000020 1E 04 1C 00 05 00 17 00 00 22 24 22 23 2C 23 23 ........."$"#,##
00000030 30 5F 29 3B 5C 28 22 24 22 23 2C 23 23 30 5C 29 0_);\("$"#,##0\)
00000040 1E 04 21 00 06 00 1C 00 00 22 24 22 23 2C 23 23 ..!......"$"#,##
00000050 30 5F 29 3B 5B 52 65 64 5D 5C 28 22 24 22 23 2C 0_);[Red]\("$"#,
00000060 23 23 30 5C 29 1E 04 22 00 07 00 1D 00 00 22 24 ##0\).."......"$
00000070 22 23 2C 23 23 30 2E 30 30 5F 29 3B 5C 28 22 24 "#,##0.00_);\("$
00000080 22 23 2C 23 23 30 2E 30 30 5C 29 1E 04 27 00 08 "#,##0.00\)..'..
00000090 00 22 00 00 22 24 22 23 2C 23 23 30 2E 30 30 5F .".."$"#,##0.00_
000000A0 29 3B 5B 52 65 64 5D 5C 28 22 24 22 23 2C 23 23 );[Red]\("$"#,##
000000B0 30 2E 30 30 5C 29 1E 04 37 00 2A 00 32 00 00 5F 0.00\)..7.*.2.._
000000C0 28 22 24 22 2A 20 23 2C 23 23 30 5F 29 3B 5F 28 ("$"* #,##0_);_(
000000D0 22 24 22 2A 20 5C 28 23 2C 23 23 30 5C 29 3B 5F "$"* \(#,##0\);_
000000E0 28 22 24 22 2A 20 22 2D 22 5F 29 3B 5F 28 40 5F ("$"* "-"_);_(@_
000000F0 29 1E 04 2E 00 29 00 29 00 00 5F 28 2A 20 23 2C )....).).._(* #,
..............
00000E70 10 00 00 4F 10 14 00 02 00 02 00 00 00 00 00 00 ...O............
00000E80 00 00 00 00 00 00 00 00 00 00 00 26 10 02 00 06 ...........&....
00000E90 00 51 10 08 00 00 01 02 00 00 00 00 00 27 10 06 .Q...........'..
00000EA0 00 04 00 02 00 FF FF 34 10 00 00 34 10 00 00 00 .......4...4....
00000EB0 02 0E 00 00 00 00 00 03 00 00 00 00 00 02 00 00 ................
00000EC0 00 0A 00 00 00 .....
OlePres000
Property: "OlePres000"
Name = "OlePres000"
Property Type = 2
Node Color = 1
Time 1 = 0
Time 2 = 0
Document: "OlePres000" size = 8098
00000000 FF FF FF FF 03 00 00 00 04 00 00 00 01 00 00 00 ................
00000010 FF FF FF FF 02 00 00 00 00 00 00 00 2F 65 00 00 ............/e..
00000020 9E 4D 00 00 60 1F 00 00 01 00 09 00 00 03 B0 0F .M..`...........
00000030 00 00 06 00 5C 0A 00 00 00 00 5C 0A 00 00 26 06 ....\.....\...&.
00000040 0F 00 AE 14 57 4D 46 43 01 00 00 00 00 00 01 00 ....WMFC........
00000050 82 02 00 00 00 00 01 00 00 00 8C 14 00 00 00 00 ................
00000060 00 00 8C 14 00 00 01 00 00 00 6C 00 00 00 A0 00 ..........l.....
00000070 00 00 02 00 00 00 4E 03 00 00 6D 02 00 00 00 00 ......N...m.....
00000080 00 00 00 00 00 00 98 62 00 00 8A 4B 00 00 20 45 .......b...K.. E
00000090 4D 46 00 00 01 00 8C 14 00 00 17 01 00 00 05 00 MF..............
000000A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................
000000B0 00 00 20 03 00 00 4A 01 00 00 CE 00 00 00 00 00 .. ...J.........
000000C0 00 00 00 00 00 00 00 00 00 00 10 09 05 00 B0 24 ...............$
000000D0 03 00 46 00 00 00 2C 00 00 00 20 00 00 00 45 4D ..F...,... ...EM
...........................
00001F50 00 00 09 02 00 00 00 00 04 00 00 00 27 01 FF FF ............'...
00001F60 03 00 00 00 1E 00 05 00 00 00 01 02 FF FF FF 00 ................
00001F70 05 00 00 00 09 02 00 00 00 00 04 00 00 00 27 01 ..............'.
00001F80 FF FF 03 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00001F90 00 00 00 00 00 00 00 00 00 00 4E 41 4E 49 00 00 ..........NANI..
00001FA0 00 00 ..
Ole
Property: "Ole"
Name = "Ole"
Property Type = 2
Node Color = 1
Time 1 = 0
Time 2 = 0
Document: "Ole" size = 20
00000000 01 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000010 00 00 00 00 ....

Re: Edit Microsoft Chart Data in pptx

PostPosted: Wed May 23, 2012 5:23 pm
by arahant7
I think it is better if I just convert this into a 2007 chart. I can then just modify the chart.xml

Re: Edit Microsoft Chart Data in pptx

PostPosted: Wed May 23, 2012 9:49 pm
by jason
Yep, or post on StackOverflow or the Apache POI mailing list.