如何用java把txt转成excel 如题,txt文件就是一般的文本文件,怎么把txt分块,然后传人excel,最好有例子,求解答 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用poi呀!正好闲着没事,给你写个灰常灰常简单的玩玩 static void txtToExcel() throws IOException { BufferedReader br = new BufferedReader(new FileReader(new File( "E:\\text.txt"))); HSSFWorkbook hwb = new HSSFWorkbook(); HSSFSheet sheet = hwb.createSheet("pldrxkxxmb"); HSSFRow firstrow = null; HSSFCell[] firstcell = null; String str = null; int i = 0; while ((str = br.readLine()) != null) { firstrow = sheet.createRow(i); firstcell = new HSSFCell[1]; firstcell[0] = firstrow.createCell(0); firstcell[0].setCellValue(str); i++; } OutputStream out = new FileOutputStream("E:\\pldrxkxxmb.xls"); hwb.write(out); out.close(); br.close(); } jacob win平台下可以用这个 要不直接保存逗号分割的 另存为 csv excel能打开具体可以看看csv说明 是大段的文本,中间参杂这逗号,要是用csv,就分的四不像了,想按内容分 LZ是说:有一大段含有标点符号的文本,现在想按逗号区分,把分开的每一段文本,写到一个excel中,对吧 /** * POI下载地址为http://poi.apache.org/ * 这里要用到poi-3.9-20121203.jar和poi-ooxml-3.9-20121203.jar */public static void writeExcel() throws IOException{ //创建一个Excel(or new XSSFWorkbook()) Workbook wb = new HSSFWorkbook(); //创建表格 Sheet sheet = wb.createSheet("测试Sheet_01"); //创建行 Row row = sheet.createRow(0); //设置行高 row.setHeightInPoints(30); //创建单元格 Cell cell = row.createCell(0); //设置单元格的值 cell.setCellValue("序号"); cell = row.createCell(1); cell.setCellValue("用户"); //标题设置完毕,下面开始填充数据 row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue("文本段01"); cell = row.createCell(1); cell.setCellValue("文本段01"); FileOutputStream fos = new FileOutputStream("D:/测试的Excel.xls"); wb.write(fos); if(null != fos){ fos.close(); } } 谢谢,还有就是假设有一段文本abbaccadd,判断遇到a就读取后面的内容,写成"bb","cc","dd"这种格式怎么写 追问,如果格式式这样的:abbaccaddd怎么写出"bb","cc","ddd",求教了 问下这样写为什么请求到不了服务器断 用JBuilder生成的jar文件不能完全运行(虽然有很多人问过,但我还是不明白) 关于system.out.println中out的简单问题,大家可以随意BS Array的问题 请各位老师给我推荐一本学JAVA的书。送50分 JLabel上的文字如何动态改变? JDBC连接oracle的问题 如何限制iframe中脚本语言的执行 我想问一下如何在一个类中改变另一个类中的数据。(我是菜鸟) 在weblogic5.1中支持perl 面向对象 关于修改文本内容的问题,代码异常,求大侠帮忙改
BufferedReader br = new BufferedReader(new FileReader(new File(
"E:\\text.txt")));
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("pldrxkxxmb");
HSSFRow firstrow = null;
HSSFCell[] firstcell = null;
String str = null;
int i = 0;
while ((str = br.readLine()) != null) {
firstrow = sheet.createRow(i);
firstcell = new HSSFCell[1];
firstcell[0] = firstrow.createCell(0);
firstcell[0].setCellValue(str);
i++;
}
OutputStream out = new FileOutputStream("E:\\pldrxkxxmb.xls");
hwb.write(out);
out.close();
br.close(); }
* POI下载地址为http://poi.apache.org/
* 这里要用到poi-3.9-20121203.jar和poi-ooxml-3.9-20121203.jar
*/
public static void writeExcel() throws IOException{
//创建一个Excel(or new XSSFWorkbook())
Workbook wb = new HSSFWorkbook();
//创建表格
Sheet sheet = wb.createSheet("测试Sheet_01");
//创建行
Row row = sheet.createRow(0);
//设置行高
row.setHeightInPoints(30);
//创建单元格
Cell cell = row.createCell(0);
//设置单元格的值
cell.setCellValue("序号");
cell = row.createCell(1);
cell.setCellValue("用户");
//标题设置完毕,下面开始填充数据
row = sheet.createRow(1);
cell = row.createCell(0);
cell.setCellValue("文本段01");
cell = row.createCell(1);
cell.setCellValue("文本段01");
FileOutputStream fos = new FileOutputStream("D:/测试的Excel.xls");
wb.write(fos);
if(null != fos){
fos.close();
}
}
abb
acc
ad
d
d
怎么写出"bb","cc","ddd",求教了