如何組,我的分組數據的每一部分都在Excel和輸出到單個數據Excel表?的Java Excel的數據進行分組
我的代碼如下: 1)從excel表格(.xlsx)獲取所有數據,並顯示它。 2)將相同的數據輸出到另一個名稱的路徑。
任何幫助/建議將不勝感激
package javaapplication8;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class JavaApplication8 {
private static String path = "";
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame();
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int option = chooser.showOpenDialog(frame); // parentComponent must a component like JFrame, JDialog...
if (option == JFileChooser.APPROVE_OPTION) {
File selectedFile = chooser.getSelectedFile();
path = selectedFile.getAbsolutePath();
}
try {
FileInputStream file = new FileInputStream(new File(path));
//Get the workbook instance for XLS file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows from first sheet
Iterator<Row> rowIterator = sheet.iterator();
while(rowIterator.hasNext()) {
Row row = rowIterator.next();
//For each row, iterate through each columns
Iterator<Cell> cellIterator = row.cellIterator();
while(cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch(cell.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "\t\t");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t\t");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t\t");
break;
}
}
System.out.println("");
}
file.close();
FileOutputStream out =
new FileOutputStream(new File("C:\\test.xlsx"));
workbook.write(out);
out.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
如果複製上面的代碼應該對任何.xlsx文件
數據樣本我試圖組的工作是:
EPPACC Cname AbarDate CTermDat MDiscDat
A4041222 Sihlaba 2011/09/16 2013/09/15 2012/11/20
A4041231 Gwavu 2011/09/26 2013/09/26 2012/11/22
A4041260 Lin 2011/11/21 2013/11/20 2012/11/29
A4041260 Lin 2011/09/16 2013/09/15 2012/11/29
A4041281 Sharma 2011/09/16 2013/09/15 2013/01/21
A4041336 Nkwankwana 2011/09/16 2013/09/15 2013/01/21
A4041336 Nkwankwana 2011/09/16 2013/09/15 2013/01/21
A4041420 Gqozo 2011/09/22 2013/09/21 2012/07/18
A4041420 Gqozo 2011/09/22 2013/09/21 2012/07/20
A4041494 Henneberry 2011/09/21 2013/09/20 2013/01/21
A4041522 Monepya 2011/09/16 2013/09/15 2013/01/21
A4041600 Vezi 2011/09/16 2013/09/15 2012/12/13
A4041640 Cupido 2011/09/27 2013/09/26 2012/09/25
A4041640 Cupido 2011/09/26 2013/09/25 2012/11/27
A4041644 Mfingwana 2011/09/27 2013/09/26 2013/01/21
A4041644 Mfingwana 2011/09/27 2013/09/27 2013/01/21
A4041665 Mafura 2011/09/29 2013/09/28 2012/12/13
A4041770 Mlangeni 2011/09/17 2013/09/16 2012/10/12
A4041965 Vukeya 2011/09/17 2013/09/17 2012/11/22
A4042005 Tayerera 2011/09/17 2013/09/16 2012/11/27
A4042005 Tayerera 2011/11/11 2013/11/10 2012/11/27
A4042005 Tayerera 2011/11/11 2013/11/10 2012/11/27
A4042005 Tayerera 2011/09/17 2013/09/16 2012/11/27
A4042029 Wallace 2011/09/17 2013/09/16 2013/01/21
A4042188 Khoza 2011/10/04 2013/10/04 2012/04/04
A4042212 Gocini 2011/09/30 2013/09/29 2012/10/29
我想分組由EPPACC
是什麼本代碼嗎?它有什麼問題? – 2013-02-28 07:34:48
本的代碼讀取的Excel文件,提取信息,將其顯示在NetBeans並且它輸出到另一個excel文件(完全相同的數據)。沒有問題,我只是不知道如何首先對數據進行分組,然後將每個分組的部分輸出到不同的Excel表格中。例如,手機目錄,您希望將不同手機的所有手機合同分組,並通過電話分組,並將每部手機的全部合同輸出到不同的工作表。 – Silentdarkness 2013-02-28 07:38:17
你能給出一個預期分組的例子嗎? – 2013-02-28 07:50:58