Excel学习1_Java读取文件中的内容写入excel中
来源:互联网 发布:日本人彻底疯了 知乎 编辑:程序博客网 时间:2024/06/05 06:30
public static void writeXls() {//把读取的文件写入到excel文件中
int i = 0;
try {
File file = new File("d:/cn.csv");
if (file.isFile() && file.exists()) {
InputStreamReader read = new InputStreamReader(
new FileInputStream(file));
BufferedReader bufferReader = new BufferedReader(read);
String lineTxt = null;
String[] arg = null;
getConnection();
List<String[]> list = new ArrayList<String[]>() ;
lineTxt = bufferReader.readLine();
try {
String tempDate;
while (lineTxt != null && !lineTxt.trim().equals("")) {
i++;
arg = lineTxt.split(",");
list.add(arg) ;
lineTxt = bufferReader.readLine();
}
for(String[] args:list){
System.out.println(args[0]+" "+args[1]+" "+args[2]+" "+args[3]);
}
operateExl(list) ;
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("文件路径不正确!");
}
} catch (Exception e) {
System.out.println("文件错误!");
} finally {
System.out.println(i);
}
}
public static void operateExl(List<String[]> list) {
try {
WritableWorkbook wb = Workbook.createWorkbook(new File("d:/test.xls")) ;
WritableSheet sheet = wb.createSheet("第一页", 0) ;
for(int i=0;i<list.size();i++){
String arg[] = list.get(i) ;
for(int j=0;j<arg.length;j++){
sheet.addCell(new Label(j,i,arg[j])) ;
}
}
wb.write() ;
wb.close() ;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace() ;
}
}
public static void main(String[] args) {
writeXls();
}
原文来自:https://yq.aliyun.com/articles/48968
- Excel学习1_Java读取文件中的内容写入excel中
- java读取文件中的内容写入excel中
- 从Excel中读取内容写入txt文件中
- EXCEL 读取 写入文件
- 读取excel,写入文件
- 读取Excel中的内容
- 【excel】读取excel 中内容
- PHP读取Excel文件的内容并写入Mysql数据库
- 读取Excel文件内容
- 读取excel文件内容
- java写入、读取excel文件1
- yii2从excel文件中读取表格内容,并批量写入数据库
- php读取excel内容并写入mysql中
- Python读取txt内容写入xls格式的excel中
- Python读取txt内容写入xlsx格式的excel中
- 读取Excel中内容
- 读取excel中内容
- 将数据库中读取的文件写入Excel文件
- LA 3942 Remember the Word——DP + 字典树
- MapStruct实体间转换
- at命令
- uva10382(贪心算法---区间覆盖问题)
- ubuntu 下ffmpeg3.3的编译
- Excel学习1_Java读取文件中的内容写入excel中
- window下MongoDB的配置与安装
- mybatis PageHelper和pageInfo的相关知识点
- adb remount 系统提示只读文件系统Read-only file system
- 【矩形】【dp】创意吃鱼法
- Python基础入门5--函数
- MyBatis简单的配置
- POJ 3321 Apple Tree dfs序 树状数组
- 【luogu1012】拼数(字符串的操作+冒泡?)