怎么样用java代码编写一个提取并打印excel表格的小程序
1个回答
展开全部
import java.io.FileInputStream;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class ReadExcel {
private Workbook workbook;// 包含的表
private Sheet sheet;// 读出第一个表
private Cell cell;// �?
private InputStream is;// 数据�?
/**
* 读取Excel文件返回�?��字符串数�?
*/
public String[][] read(String filename) {
String[][] temp = null;
try {
is = new FileInputStream(filename);
workbook = Workbook.getWorkbook(is);
// 获得第一个工作表对象
sheet = workbook.getSheet(0);
// 得到第一列第�?��的单元格
int i = 0;
int j = 0;
int rows = sheet.getRows();
int columns = sheet.getColumns();
temp = new String[rows][columns];
for (i = 0; i < rows; i++) {
for (j = 0; j < columns; j++) {
cell = sheet.getCell(j, i);
temp[i][j] = cell.getContents();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return temp;
}
}
后面的自己写
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class ReadExcel {
private Workbook workbook;// 包含的表
private Sheet sheet;// 读出第一个表
private Cell cell;// �?
private InputStream is;// 数据�?
/**
* 读取Excel文件返回�?��字符串数�?
*/
public String[][] read(String filename) {
String[][] temp = null;
try {
is = new FileInputStream(filename);
workbook = Workbook.getWorkbook(is);
// 获得第一个工作表对象
sheet = workbook.getSheet(0);
// 得到第一列第�?��的单元格
int i = 0;
int j = 0;
int rows = sheet.getRows();
int columns = sheet.getColumns();
temp = new String[rows][columns];
for (i = 0; i < rows; i++) {
for (j = 0; j < columns; j++) {
cell = sheet.getCell(j, i);
temp[i][j] = cell.getContents();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return temp;
}
}
后面的自己写
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询