Hi, I don't think this is a valid Sheet name and I would try to simply avoid it if possible as XML does not allow control characters at all (at least in XML 1.0), I think the best we could do in POI would be to throw an error if we find these characters, however this would slow down processing as we would need to check every place where any string can appear...
if you try to enter this name in Excel, do you manage to get really this written to the file? How does it look like in the XLSX (opened with a zip-tool looking at xl/workbook.xml)? Thanks... Dominik. On Mon, Oct 6, 2014 at 11:19 AM, Robert Gurol <[email protected]> wrote: > Hi again, > > I finally had the time to make this into a JUnit test, I was going to > submit it as a bug to bugzilla, but encountered a bug during > registration... > > For now, I will attach the JUnit code below (POI 3.9) > > Regards, > > Robert > > package poi.test; > > import static org.junit.Assert.*; > > import java.io.FileInputStream; > import java.io.FileOutputStream; > > import org.apache.poi.ss.usermodel.Cell; > import org.apache.poi.ss.usermodel.Row; > import org.apache.poi.ss.usermodel.Sheet; > import org.apache.poi.ss.usermodel.Workbook; > import org.apache.poi.xssf.usermodel.XSSFWorkbook; > import org.junit.Test; > > > public class PoiControlCharacterTest { > private static final String PATH = "./myFile.xlsx"; > > @Test > public void testControlCharactersInSheetNames() throws Exception { > Workbook wb = new XSSFWorkbook(); > String cellValue = "Test"; > // String sheetName = "MySheet"; // works > String sheetName = "\u001f"; // can be written, but never opened > Sheet s = wb.createSheet(sheetName); > Row row = s.createRow(0); > Cell cell = row.createCell(0); > cell.setCellValue(cellValue); > FileOutputStream fos = new FileOutputStream(PATH); > wb.write(fos); > fos.close(); > // do not crash when opening > // bug causes org.apache.poi.POIXMLException: > org.apache.xmlbeans.XmlException: error: Illegal XML character: 0x1f > Workbook wb2 = new XSSFWorkbook(new FileInputStream(PATH)); > Sheet s2 = wb2.getSheetAt(0); > assertEquals(sheetName, s2.getSheetName()); > assertEquals(cellValue, s2.getRow(0).getCell(0).getStringCellValue()); > } > } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
