Read:
Public static void main (string [] ARGs) throws exception {
String filepath = "d :\\ test.xls ";
Workbook book = Workbook. getworkbook (new file (filepath ));
// Obtain the first worksheet object
Sheet sheet = book. getsheet (0 );
// Obtain the cell in the second row of the first column
Cell cell1 = sheet. getcell (0, 1 );
String result = cell1.getcontents ();
System. Out. println (result );
Book. Close ();
}
Operation modification:
Public class jxlmodify {
Public static void main (string [] ARGs) throws exception
{
// Obtain the Excel file
String filepath = "d :\\ test.xls ";
Workbook WB = Workbook. getworkbook (new file (filepath ));
// Open a copy of a file and write the data back to the source file
Note that the second parameter here is the Excel parameter obtained above.
Writableworkbook book = Workbook. createworkbook (new file (filepath), WB );
// Obtain the first table
Writablesheet oldsheet = book. getsheet (0 );
Label L = new label (0, 1, "Modify Test ID ");
Oldsheet. addcell (L );
// Add a new worksheet
Writablesheet sheet = book. createsheet ("second table", 1 );
Label L = new label (0, 0, "test data on the second page ");
Sheet. addcell (L );
// Close
Book. Write ();
Book. Close ();
}
}
Operate images (note the image format:
Warning: Image Type JPEG not supported. Supported types are PNG
)
Public static void main (string [] ARGs) throws exception {
String filepath = "d :\\ test.xls ";
Workbook WB = Workbook. getworkbook (new file (filepath ));
Writableworkbook WWB = Workbook. createworkbook (new file (filepath), WB );
Writablesheet sheet = WWB. getsheet (2 );
File imagefile = new file ("D: \ jxl.png ");
//Five parameters (row column) span (row column) file objects
Writableimage image = new writableimage (1, 4, 2, 2, imagefile );
// Write Method
Sheet. addimage (image );
WWB. Write ();
WWB. Close ();
}
Cell operations:
Writablesheet. setrowview (int I, int height); // specify the height of row I + 1
Writablesheet. setcolumnview (int I, int width); // specify the width of column I + 1