You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by 董青 <dq...@gmail.com> on 2011/09/22 14:49:54 UTC
InternalSheet serialize?
I read a topic from another site showing this function.
The code is written under POI 3.1. But some classes have another names in
POI 3.7. I found Workbook changed to InternalWorkbook and Sheet changed to
InternalSheet. But some function in the classes is no longer exist.
Now I meet this problem that I can preSerialize() the InternalSheet, But I
can't serialize it. The functions I didn't find are figured out below.
I need some help. Thank you.
1. static byte[] getBytes(Workbook workbook, Sheet[] sheets) {
2. int nSheets = sheets.length;
3.
4. for(int i = 0; i < nSheets; i++){
5. sheets[i].preSerialize();
6. }
7.
8. int totalsize = workbook.getSize();
9.
10. int[] estimatedSheetSizes = new int[nSheets];
11. for(int k = 0; k < nSheets; k++){
12. workbook.setSheetBof(k, totalsize);
13. int sheetSize = sheets[k].getSize(); ------------I
can't find this getSize()
14. estimatedSheetSizes[k] = sheetSize;
15. totalsize += sheetSize;
16. }
17.
18. byte[] retval = new byte[totalsize];
19. int pos = workbook.serialize(0, retval); ------------AND
I can't find this serialize() either.
20.
21. for(int k = 0; k < nSheets; k++){
22. int
serializedSize = sheets[k].serialize(pos, retval);
23. if(serializedSize != estimatedSheetSizes[k]){
24. throw new IllegalStateException(
"Actual serialized sheet size (" + serializedSize
25. + ") differs from pre-calculated size ("
+ estimatedSheetSizes[k] + ") for sheet (" + k
26. + ")");
27. }
28. pos += serializedSize;
29. }
30. return retval;
31. }