Java code
/*************************************** *****************************
*
* (C) Copyright ISFnet Japan, Ltd. 2011 All rights reserved.
*
**************************************** ****************************/
Package excel;
Import java. io. FileInputStream;
Import java. io. FileNotFoundException;
Import java. io. FileOutputStream;
Import java. io. IOException;
Import org. apache. poi. hssf. usermodel. HSSFSheet;
Import org. apache. poi. hssf. usermodel. HSSFWorkbook;
Import org. apache. poi. poifs. filesystem. POIFSFileSystem;
Import org. apache. poi. ss. usermodel. Cell;
Import org. apache. poi. ss. usermodel. Row;
Import org. apache. poi. ss. util. CellRangeAddress;
/**
* <P>
*
* @ Author ISFnet DALIAN muzongqin
* @ Since 2011/08/10
* @ Version 1.0
*/
Public class CopyExcel {
/**
*
*
*
* @ Param args
* Void
* @ Throws IOException
* @ Throws FileNotFoundException
*/
Public static void main (String [] args) throws FileNotFoundException, IOException {
// You can see the following information.
Final String INVOICE_FILE = "C: \ work \ jyuchu \ 3_ .......xls ";
// When there are too many attempts, there are too many attempts.
POIFSFileSystem filein = new POIFSFileSystem (new FileInputStream (INVOICE_FILE ));
// When there are too many attempts, there are too many attempts.
HSSFWorkbook wb = new HSSFWorkbook (filein );
// When there are too many threads, there are too many threads.
HSSFSheet sheet1 = wb. getSheet (" ");
HSSFSheet sheet2 = wb. createSheet ("Notify supervisor 1 ");
Sheet2 = copySheet (sheet1, sheet2 );
FileOutputStream fileOut = new FileOutputStream ("d: \ test1.xls ");
Wb. write (fileOut );
FileOut. close ();
}
Private static HSSFSheet copySheet (HSSFSheet sheetFrom, HSSFSheet sheetTo ){
// Initial Stage
CellRangeAddress region = null;
Row rowFrom = null;
Row rowTo = null;
Cell cellFrom = null;
Cell cellTo = null;
// When combined, when combined
For (int I = 0; I <sheetFrom. getNumMergedRegions (); I ++ ){
Region = sheetFrom. getMergedRegion (I );
If (region. getFirstColumn ()> = sheetFrom. getFirstRowNum ())
& (Region. getLastRow () <= sheetFrom. getLastRowNum ())){
SheetTo. addMergedRegion (region );
}
}
// Please wait until then
For (int intRow = sheetFrom. getFirstRowNum (); intRow <sheetFrom. getLastRowNum (); intRow ++ ){
RowFrom = sheetFrom. getRow (intRow );
RowTo = sheetTo. createRow (intRow );
If (null = rowFrom)
Continue;
RowTo. setHeight (rowFrom. getHeight ());
For (int intCol = 0; intCol <rowFrom. getLastCellNum (); intCol ++ ){
// Adjust the bandwidth and then adjust the bandwidth
SheetTo. setdefacolumcolumnstyle (intCol, sheetFrom. getColumnStyle (intCol ));
SheetTo. setColumnWidth (intCol, sheetFrom. getColumnWidth (intCol ));
CellFrom = rowFrom. getCell (intCol );
CellTo = rowTo. createCell (intCol );
If (null = cellFrom)
Continue;
// When there are too many threads, there are too many other threads.
CellTo. setCellStyle (cellFrom. getCellStyle ());
CellTo. setCellType (cellFrom. getCellType ());
// Too many contents
If (null! = CellFrom. getStringCellValue ()&&! "". Equals (cellFrom. getStringCellValue (). trim ()))
CellTo. setCellValue (cellFrom. getStringCellValue ());
}
}
// Configure your instances
SheetTo. setDisplayGridlines (false );
// Set the Excel worksheet.
SheetTo. setZoom (80,100 );
// Please wait until then.
Return sheetTo;
}
}