文档彩票走势图>>Spire.XLS 系列教程>>Spire.XLS教程:在 Java 中将工作表从一个工作簿复制到另一个工作簿
Spire.XLS教程:在 Java 中将工作表从一个工作簿复制到另一个工作簿
Spire.XLS for Java是专业的Java Excel API,使开发人员无需使用Microsoft Office或Microsoft Excel即可创建,管理,操作,转换和打印Excel工作表。
本文展示了如何通过使用Spire.XLS for Java将一个工作表从一个Excel文档复制到另一个。
代码如下:
import com.spire.xls.Workbook; import com.spire.xls.Worksheet; public class CopySheetBetweenWorkbooks { public static void main(String[] args) { //Create a Workbook object to load the source document Workbook srcWorkbook = new Workbook(); srcWorkbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\source.xlsx"); //Get the specific worksheet to copy Worksheet originalSheet = srcWorkbook.getWorksheets().get(0); //Create another Workbook object to load the destination document Workbook destWorkbook = new Workbook(); destWorkbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\destination.xlsx"); //Add the copy of selected sheet to destination document Worksheet newSheet = destWorkbook.getWorksheets().addCopy(originalSheet); newSheet.setName(originalSheet.getName()); //Copy the theme of source document to destination document destWorkbook.copyTheme(srcWorkbook); //Save to another file destWorkbook.saveToFile("CopySheetBetweenWorkbooks.xlsx"); } }
慧都是E-iceblue官方友好合作伙伴,如果您对spire.xls,可以了解具体授权价格和使用机制