I am attempting to write to an Excel file however I keep getting the error:
Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
From what I understand I am missing a jar file.
Can anyone help me identify which file it is?
P.S. I am using Netbeans.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* @author nicholaskissaun
*/
public class Tester {
public static void main (String args \[\])throws FileNotFoundException, IOException, InvalidFormatException{
int RowCount = 7, iChoice;
String sChoice;
XSSFSheet s;
XSSFRow row1;
XSSFWorkbook wb;
XSSFCell r1c1, r1c2, r1c8, r1Episodes;
FileInputStream fis = new FileInputStream("/Users/nicholaskissaun/Google Drive/Grade 11_12/Computer Science/Java/Term1/src/IA/Profiles/Becky/ShowDetails.xlsx");
wb = new XSSFWorkbook(fis);
s = wb.getSheetAt(0);
}
}
The excel file which your application trying to access is not responding due to network issues or corrupted format causes this error. If it is due to network issue try to run application later (or) If file is corrupted, try to put new file and test your application. Good Luck.
This may happen when your create your XLS/XLSX file through LibreOffice. Apparently something is lost in the conversion and the file is not the same as a spreadsheet made in Microsoft Office. I had the same error and the solution for me was copying all the work I have done in LibreOffice Calc to a MS Excel spreadsheet and then save a new file.
CHECK EXCEL FORMAT .... Firstly I created an sample excel with poi and I changed the columns with mine first attempt it give same error but after few try it successfully read .I wonder why it didn't worked first run :( but If you have right library please check the correct excel format
Use file extension to handle
WorkSheet
TypeFor XLSX file: use
XSSFWorkbook & XSSFSheet
For XLS file: use
HSSFWorkbook & HSSFSheet
I got the same problem. Your excel isn't in right format. You can copy all work to new sheet or do Clear Format. Good luck.
I have the same problem. When you open excel file it will generate some file like ~$______.xlsx Just find and delete all of them worked for me.