You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by DSantosh2 <sa...@gmail.com> on 2014/01/22 12:00:24 UTC

Re: org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]

		try {
		File file = new File(path);
		FileInputStream is =new FileInputStream(file);
		FileOutputStream  outputStream = new FileOutputStream(file);
		XSSFWorkbook workbook = new XSSFWorkbook(is);
		int index = workbook.getSheetIndex("Sheet1");
		XSSFSheet xssfSheet;
		if(index < 0)
		{
			xssfSheet = workbook.createSheet();
		}
		else
		{
		  xssfSheet = workbook.getSheetAt(index);
		}
		XSSFRow xssfRow = xssfSheet.getRow(0);
		
		if(null == xssfRow)
		{
			xssfRow = xssfSheet.createRow(0);
		}
		XSSFCell cell;
		
		XSSFCellStyle style = workbook.createCellStyle();
		style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
		style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		
		if(xssfRow.getLastCellNum() == -1)
			cell = xssfRow.createCell(0);
		else
			cell = xssfRow.createCell(xssfRow.getLastCellNum());
		
		cell.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell.setCellValue("Result");
		cell.setCellStyle(style);
		/*
		for(int  i = 1 ; i<rowCount ; i++ )
		{
			xssfRow = xssfSheet.getRow(i);
			cell = xssfRow.createCell(3);
			cell.setCellType(XSSFCell.CELL_TYPE_STRING);
			cell.setCellValue("pass");
		}
		*/
			workbook.write(outputStream);
			outputStream.flush();
			outputStream.close();
			is.close();
		} catch (IOException e) {
			// TestExcel
			e.printStackTrace();
		} catch (Exception e) {
		
			e.printStackTrace();
		}
	

This is my code but still i'm getting the above exception. Can any one
please help me in this issue



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/org-apache-poi-POIXMLException-org-apache-poi-openxml4j-exceptions-InvalidFormatException-Package-sh-tp5711375p5714719.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]

Posted by Nick Burch <ap...@gagravarr.org>.
On Wed, 22 Jan 2014, DSantosh2 wrote:
> This is my code but still i'm getting the above exception. Can any one 
> please help me in this issue

What version of POI are you using? Where did the Excel file come from? Can 
Excel open it without error? Can you share the problematic file?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org