Lines 1374-1407
public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
Link Here
|
1374 |
{ |
1374 |
{ |
1375 |
byte[] bytes = getBytes(); |
1375 |
byte[] bytes = getBytes(); |
1376 |
NPOIFSFileSystem fs = new NPOIFSFileSystem(); |
1376 |
NPOIFSFileSystem fs = new NPOIFSFileSystem(); |
|
|
1377 |
try { |
1377 |
|
1378 |
|
1378 |
// For tracking what we've written out, used if we're |
1379 |
// For tracking what we've written out, used if we're |
1379 |
// going to be preserving nodes |
1380 |
// going to be preserving nodes |
1380 |
List<String> excepts = new ArrayList<String>(1); |
1381 |
List<String> excepts = new ArrayList<String>(1); |
1381 |
|
1382 |
|
1382 |
// Write out the Workbook stream |
1383 |
// Write out the Workbook stream |
1383 |
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook"); |
1384 |
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook"); |
1384 |
|
1385 |
|
1385 |
// Write out our HPFS properties, if we have them |
1386 |
// Write out our HPFS properties, if we have them |
1386 |
writeProperties(fs, excepts); |
1387 |
writeProperties(fs, excepts); |
1387 |
|
1388 |
|
1388 |
if (preserveNodes) { |
1389 |
if (preserveNodes) { |
1389 |
// Don't write out the old Workbook, we'll be doing our new one |
1390 |
// Don't write out the old Workbook, we'll be doing our new one |
1390 |
// If the file had an "incorrect" name for the workbook stream, |
1391 |
// If the file had an "incorrect" name for the workbook stream, |
1391 |
// don't write the old one as we'll use the correct name shortly |
1392 |
// don't write the old one as we'll use the correct name shortly |
1392 |
excepts.addAll(Arrays.asList(WORKBOOK_DIR_ENTRY_NAMES)); |
1393 |
excepts.addAll(Arrays.asList(WORKBOOK_DIR_ENTRY_NAMES)); |
1393 |
|
1394 |
|
1394 |
// Copy over all the other nodes to our new poifs |
1395 |
// Copy over all the other nodes to our new poifs |
1395 |
EntryUtils.copyNodes( |
1396 |
EntryUtils.copyNodes( |
1396 |
new FilteringDirectoryNode(this.directory, excepts) |
1397 |
new FilteringDirectoryNode(this.directory, excepts) |
1397 |
, new FilteringDirectoryNode(fs.getRoot(), excepts) |
1398 |
, new FilteringDirectoryNode(fs.getRoot(), excepts) |
1398 |
); |
1399 |
); |
1399 |
|
1400 |
|
1400 |
// YK: preserve StorageClsid, it is important for embedded workbooks, |
1401 |
// YK: preserve StorageClsid, it is important for embedded workbooks, |
1401 |
// see Bugzilla 47920 |
1402 |
// see Bugzilla 47920 |
1402 |
fs.getRoot().setStorageClsid(this.directory.getStorageClsid()); |
1403 |
fs.getRoot().setStorageClsid(this.directory.getStorageClsid()); |
|
|
1404 |
} |
1405 |
fs.writeFilesystem(stream); |
1406 |
} finally { |
1407 |
fs.close(); |
1403 |
} |
1408 |
} |
1404 |
fs.writeFilesystem(stream); |
|
|
1405 |
} |
1409 |
} |
1406 |
|
1410 |
|
1407 |
/** |
1411 |
/** |