Problem 1:unable to recognize OLE stream format issue to be possible because the data that is given is the 2010 data table suffix of. xlsx, to be converted first to version 2003 with the suffix. xls problem 2:warning:property Storage Name for5 is empty-setting to Root entry may be Jxl.jar does not support Excel5.0 forMac, this problem occurs when importing under Mac. //reading data from Excel rownum rows Public Static Double[] Readexcel (File excelfile,intRowNum)throwsbiffexception,ioexception{Double[] Datax =New Double[1000]; Workbook RWB=NULL; Cell Cell=NULL; InputStream Stream=NewFileInputStream (excelfile); RWB=Workbook.getworkbook (stream);//gets the specified sheet default to the firstSheet Sheet= Rwb.getsheet (0);//number of rows, where reading begins reading from the second row for(inti = 1; I <= rowNum; i++) {String str=NewString ();//Here you select the number of columns and rows of data to read for example (3,4) description is the fourth row of the third column, and the number of rows is counted from 0 onwardsCell= Sheet.getcell (3, i); Str=cell.getcontents ();d atax[i-1] =double.parsedouble (str);//The following is to print the data to see if the data read is correctSystem.out.println ("Data" + (i-1) + ":" +datax[i-1]);}returndatax;}//to store data in an Excel table Public Static voidCreatexcel (File Outfilename,Double[] risks)throwsbiffexception, ioexception,writeexception {//get the output streamoutputstream OS=NewFileOutputStream (outfilename); Writableworkbook Workbook=workbook.createworkbook (OS);//Specify the name of the data table you are storing hereWritablesheet Sheet= Workbook.createsheet ("Deutsche", 1); Label parameter=NewLabel (1, 1, "1/Alpha"); Sheet.addcell (parameter); for(inti = 0; i < risks.length; i++) {Number risk=NewNumber (1,i+2, Risks[i]); Sheet.addcell (risk);}//writes data from the output stream to Excel, closes the output streamworkbook.write (); Workbook.close (); Os.close ();} Some table structures::: Label formate=NewLabel (0,0, "Data format"); Sheet.addcell (formate); Label Floats=NewLabel (1, 0, "floating-point"); Sheet.addcell (floats); Label integers=NewLabel (2,0, "integer"); Sheet.addcell (integers); Label Booleans=NewLabel (3,0, "Boolean"); Sheet.addcell (Booleans); Label dates=NewLabel (4,0, "date format"); Sheet.addcell (dates); Label Example=NewLabel (0,1, "Data sample"); Sheet.addcell (example); //floating point DataNumber number =NewNumber (1,1,3.1415926535); Sheet.addcell (number); //Shaping DataNumber INTs =NewNumber (2,1,15042699); Sheet.addcell (INTs); Boolean Bools=NewBoolean (3,1,true); Sheet.addcell (Bools); //Date type DataCalendar C =calendar.getinstance (); Date Date=C.gettime (); Writablecellformat CF1=NewWritablecellformat (DATEFORMATS.FORMAT1); DateTime DT=NewDateTime (4,1, DATE,CF1); Sheet.addcell (DT);}//complex layouts and styles: :: Public classMutistyleexcelwrite { Public voidCreateexcel (OutputStream OS)throwswriteexception,ioexception {//Create a workbookWritableworkbook Workbook =workbook.createworkbook (OS); //Create a new pageWritablesheet sheet = workbook.createsheet ("First sheet", 0); //construct a table headerSheet.mergecells (0, 0, 4, 0);//to add a merged cell, the first parameter is the starting column, the second argument is the starting row, the third parameter is the terminating column, and the fourth argument is the terminating rowWritablefont Bold =NewWritablefont (Writablefont.arial,10,writablefont.bold);//set font type and bold display with Arial, font size 10, boldWritablecellformat titleformate =NewWritablecellformat (bold);//generate a cell style control objectTitleformate.setalignment (Jxl.format.Alignment.CENTRE);//the contents of the cell are centered horizontallyTitleformate.setverticalalignment (Jxl.format.VerticalAlignment.CENTRE);//the contents of the cell are centered verticallyLabel title =NewLabel (0,0, "JEXCELAPI support data type detailed description", titleformate); Sheet.setrowview (0, 600,false);//set the height of the first rowSheet.addcell (title); //create the specific content to displayWritablefont color =NewWritablefont (writablefont.arial);//Select FontColor.setcolour (Colour.gold);//set the font color to golden yellowWritablecellformat ColorFormat =NewWritablecellformat (color); Label formate=NewLabel (0,1, "data format", ColorFormat); Sheet.addcell (formate); Label Floats=NewLabel (1, 1, "floating-point"); Sheet.addcell (floats); Label integers=NewLabel (2,1, "integer"); Sheet.addcell (integers); Label Booleans=NewLabel (3,1, "Boolean"); Sheet.addcell (Booleans); Label dates=NewLabel (4,1, "date format"); Sheet.addcell (dates); Label Example=NewLabel (0,2, "Data sample", ColorFormat); Sheet.addcell (example); //floating point Data//Set UnderlineWritablefont underline=NewWritablefont (Writablefont.arial,writablefont.default_point_size,writablefont.no_bold,false, Underlinestyle.single); Writablecellformat Greybackground=NewWritablecellformat (underline); Greybackground.setbackground (colour.gray_25);//set the background color to grayNumber number =NewNumber (1,2,3.1415926535, Greybackground); Sheet.addcell (number); //Shaping DataWritablefont Boldnumber =NewWritablefont (Writablefont.arial,10,writablefont.bold);//blackbodyWritablecellformat boldnumberformate =NewWritablecellformat (Boldnumber); Number INTs=NewNumber (2,2,15042699, boldnumberformate); Sheet.addcell (INTs); //Boolean type dataBoolean Bools =NewBoolean (3,2,true); Sheet.addcell (Bools); //Date type Data//set Bold and underlineWritablefont bolddate =NewWritablefont (Writablefont.arial,writablefont.default_point_size,writablefont.bold,false, Underlinestyle.single); Writablecellformat bolddateformate=NewWritablecellformat (BOLDDATE,DATEFORMATS.FORMAT1); Calendar C=calendar.getinstance (); Date Date=C.gettime (); DateTime DT=NewDateTime (4,2, date,bolddateformate); Sheet.addcell (DT); //writes the created content to the output stream and closes the output streamWorkbook.write (); Workbook.close (); Os.close (); }
Java implements reading and writing of Excel table data and possible problems in the process