請問一下是excel的行轉(zhuǎn)列嗎 ???寫了個工具類解決了。
創(chuàng)新互聯(lián)是一家專業(yè)提供墾利企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計、成都做網(wǎng)站、H5頁面制作、小程序制作等業(yè)務(wù)。10年已為墾利眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。
public MapString,String getColumnToRow(String path,int x,int y){
MapString,SetString map=new HashMap();
String[][] str=ExcelHelper.poiReader(path, null);
for(int i=1;istr.length;i++){
String cid=str[i][x];
String brandname=str[i][y];
if(map.get(cid)==null){
SetString set=new HashSet();
set.add(brandname);
map.put(cid, set);
}else{
SetString set=map.get(cid);
set.add(brandname);
map.put(cid, set);
}
}
MapString,String result=new HashMap();
for(String cid:map.keySet()){
SetString set=map.get(cid);
String xx="";
for(String s:set){
xx+=s+",";
}
result.put(cid, xx);
}
return result;
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
//注意這里沒有對你的數(shù)據(jù)的空格加以處理,只處理單空格的數(shù)據(jù)行,6357VS 20110111 1 也就是說,目前這三個數(shù)據(jù)之間只允許有一個空格。需要你來擴充對任意空格數(shù)的處理。
public class LineTransfer {
public static void main(String[] args) {
File f = new File("dat.txt");
BufferedReader buf=null;
File save = new File("d:/data.TAR");
String []strArr ;
BufferedWriter bw=null;
try {
bw = new BufferedWriter(new FileWriter(save));
buf = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
String value= buf.readLine();
while((value=buf.readLine())!=null){
strArr = value.split(" ");
bw.write("S"+strArr[0]);
bw.newLine();
bw.write("T"+strArr[1]);
bw.newLine();
bw.write(strArr[2]);
bw.newLine();
}
bw.flush();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
1.使用java中的轉(zhuǎn)義符"\r\n":
Java代碼 String str="aaa"; str+="\r\n"; 這樣在str后面就有換行了.
注意:\r,\n的順序是不能夠?qū)Q的,否則不能實現(xiàn)換行的效果.
2.BufferedWriter的newline()方法:
Java代碼 FileOutputStream fos=new FileOutputStream("c;\\11.txt"); BufferedWriter bw=new BufferedWriter(fos); bw.write("你好"); bw.newline(); bw.write("java"); w.newline(); 3.使用System.getProperty()方法:
Java代碼 String str = "aaa"+System.getProperty("line.separator"); 后記:
windows和linux/unix平臺中應(yīng)該沒有通用的換行符的。針對常用的系統(tǒng),可以使用如下的轉(zhuǎn)義符實現(xiàn)換行:
windows下的文本文件換行符:\r\n
linux/unix下的文本文件換行符:\rMac下的文本文件換行符:\n
名稱欄目:java代碼實現(xiàn)行轉(zhuǎn)列 java實現(xiàn)動態(tài)行轉(zhuǎn)列
文章地址:http://muchs.cn/article48/doesdhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、搜索引擎優(yōu)化、動態(tài)網(wǎng)站、網(wǎng)站建設(shè)、企業(yè)建站、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)