Kaynağa Gözat

Bug #53404 - Fixed compatibility issue with modifying xls files created by POI-3.6 and earlier

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1402186 13f79535-47bb-0310-9956-ffa450edef68
tags/3.10-beta1
Yegor Kozlov 11 yıl önce
ebeveyn
işleme
146345aef8

+ 1
- 0
src/documentation/content/xdocs/status.xml Dosyayı Görüntüle



<changes> <changes>
<release version="3.9-beta1" date="2012-??-??"> <release version="3.9-beta1" date="2012-??-??">
<action dev="poi-developers" type="add">53404 - Fixed compatibility bug with modifying xls files created by POI-3.6 and earlier</action>
<action dev="poi-developers" type="add">53979 - Support fetching properties of Numbered Lists from PPT files</action> <action dev="poi-developers" type="add">53979 - Support fetching properties of Numbered Lists from PPT files</action>
<action dev="poi-developers" type="add">53784 - Partial HSMF support for fixed sized properties</action> <action dev="poi-developers" type="add">53784 - Partial HSMF support for fixed sized properties</action>
<action dev="poi-developers" type="add">53943 - added method processSymbol() to allow converting word symbols </action> <action dev="poi-developers" type="add">53943 - added method processSymbol() to allow converting word symbols </action>

+ 21
- 10
src/java/org/apache/poi/hssf/model/InternalWorkbook.java Dosyayı Görüntüle

boundsheets.add(bsr); boundsheets.add(bsr);
getOrCreateLinkTable().checkExternSheet(sheetnum); getOrCreateLinkTable().checkExternSheet(sheetnum);
fixTabIdRecord(); fixTabIdRecord();
} else {
// Ensure we have enough tab IDs
// Can be a few short if new sheets were added
if(records.getTabpos() > 0) {
TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos());
if(tir._tabids.length < boundsheets.size()) {
fixTabIdRecord();
}
}
} }
} }


/** /**
* make the tabid record look like the current situation. * make the tabid record look like the current situation.
* *
* @return number of bytes written in the TabIdRecord
*/ */
private void fixTabIdRecord() {
private int fixTabIdRecord() {
TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos()); TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos());
int sz = tir.getRecordSize();
short[] tia = new short[ boundsheets.size() ]; short[] tia = new short[ boundsheets.size() ];


for (short k = 0; k < tia.length; k++) { for (short k = 0; k < tia.length; k++) {
tia[ k ] = k; tia[ k ] = k;
} }
tir.setTabIdArray(tia); tir.setTabIdArray(tia);
return tir.getRecordSize() - sz;

} }


/** /**
return pos; return pos;
} }


/**
* Perform any work necessary before the workbook is about to be serialized.
*
* Include in it ant code that modifies the workbook record stream and affects its size.
*/
public void preSerialize(){
// Ensure we have enough tab IDs
// Can be a few short if new sheets were added
if(records.getTabpos() > 0) {
TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos());
if(tir._tabids.length < boundsheets.size()) {
fixTabIdRecord();
}
}
}

public int getSize() public int getSize()
{ {
int retval = 0; int retval = 0;

+ 2
- 0
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Dosyayı Görüntüle

HSSFSheet[] sheets = getSheets(); HSSFSheet[] sheets = getSheets();
int nSheets = sheets.length; int nSheets = sheets.length;



// before getting the workbook size we must tell the sheets that // before getting the workbook size we must tell the sheets that
// serialization is about to occur. // serialization is about to occur.
workbook.preSerialize();
for (int i = 0; i < nSheets; i++) { for (int i = 0; i < nSheets; i++) {
sheets[i].getSheet().preSerialize(); sheets[i].getSheet().preSerialize();
sheets[i].preSerialize(); sheets[i].preSerialize();

+ 20
- 4
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Dosyayı Görüntüle

import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;


import java.io.*; import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.*;


/** /**
* Testcases for bugs entered in bugzilla * Testcases for bugs entered in bugzilla


wb = writeOutAndReadBack((HSSFWorkbook) wb); wb = writeOutAndReadBack((HSSFWorkbook) wb);
} }

public void test53404(){
Workbook wb = openSample("53404.xls");
Sheet sheet = wb.getSheet("test-sheet");
int rowCount = sheet.getLastRowNum() + 1;
int newRows = 5;
for (int r = rowCount; r < rowCount + newRows; r++) {
Row row = sheet.createRow((short) r);
row.createCell(0).setCellValue(1.03 * (r + 7));
row.createCell(1).setCellValue(new Date());
row.createCell(2).setCellValue(Calendar.getInstance());
row.createCell(3).setCellValue(String.format("row:%d/col:%d", r, 3));
row.createCell(4).setCellValue(true);
row.createCell(5).setCellType(Cell.CELL_TYPE_ERROR);
row.createCell(6).setCellValue("added cells.");
}

wb = writeOutAndReadBack((HSSFWorkbook) wb);
}
} }

BIN
test-data/spreadsheet/53404.xls Dosyayı Görüntüle


Loading…
İptal
Kaydet