mình có một file "myfile.xls" trong thẻ nhớ. vậy mình làm cách nào hay dung libs nào để đọc được file này. giúp mình với.
mình lên google thì có đoạn code này nhưng khi chạy thì nó báo không tìm thấy file.
Mã nguồn PHP:
[color=#000000]
string path [/color][color=#007700]= [/color][color=#0000bb]environment[/color][color=#007700].[/color][color=#0000bb]getexternalstoragedirectory[/color][color=#007700]().[/color][color=#0000bb]getabsolutepath[/color][color=#007700]() + [/color][color=#dd0000]"/myfile.xls"[/color][color=#007700]; [/color][color=#0000bb]init[/color][color=#007700]([/color][color=#0000bb]path[/color][color=#007700]); [/color]
Mã:
public void init(string filepath) {
// todo auto-generated method stub
fileinputstream fs = null;
try{
fs = new fileinputstream(new file(filepath));
contentreading(fs);
}catch(exception e){
e.printstacktrace();
}
}
public void contentreading(inputstream fileinputstream){
workbooksettings ws = null;
workbook workbook = null;
sheet s = null;
cell rowdata[] = null;
int rowcount = '0';
int columncont = '0';
int totalsheet = '0';
try{
ws = new workbooksettings();
ws.setlocale(new locale("en", "en"));
workbook = workbook.getworkbook(fileinputstream);
totalsheet = workbook.getnumberofsheets();
if(totalsheet > 0){
for(int j =0; j < totalsheet; j++){
system.out.println("sheet name: " + workbook.getsheet(j).getname());
}
}
sheet sheet = workbook.getsheet(0);
// get number row and col contain data
int rows = sheet.getrows();
int cols = sheet.getcolumns();
system.out.println("data in file:");
// read data in each cell
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
cell cell = sheet.getcell(col, row);
system.out.print(cell.getcontents() + "\t");
}
system.out.println("
");
}
// close
workbook.close();
} catch (biffexception e) {
system.out.println("file not found
" + e.tostring());
} catch (ioexception e) {
system.out.println("file not found
" + e.tostring());
}
}
Xe tải Veam VT260-1 tải trọng 1,9 tấn là mẫu xe mang kiểu dáng hoàn toàn khác biệt so với dòng xe phiên bản trước ấy của Veam là VT260-1. Dù đã ra mắt 2018 nhưng tới bây giờ VT260-1 vẫn được nhiều...
Đánh giá Xe Veam VT260 1.9 tấn