Copying Sheet to another workbook

Jan 15, 2010 at 5:58 PM

Is there any way to copy a sheet from one workbook to another workbook?

Sep 15, 2010 at 9:16 AM

这个其实很简单的。具体的做法是:

首先复制一个完整的sheet,就是你要Copy的那个sheet,然后把所有的行和行号放到字典中

然后就是在一个新的workbook中创建一个新的sheet

最后就是创建行、创建单元格了。

Sep 16, 2010 at 2:11 AM

try this:

 public string CloneAndCreateSheet(Workbook workbook, Sheet sheet)
        {
            if (workbook == null || sheet == null)
            {
                return "";
            }
            Sheet newsheet;
            newsheet = workbook.CloneSheet(2);
            return newsheet.SheetName;
        }

Sep 16, 2010 at 6:15 AM

Thank you for the code

Sep 16, 2010 at 7:48 AM

        /// <summary>
        /// 复制并且创建一个新的worksheet,此处涉及到合并单元格和单元格的属性问题
        /// </summary>
        /// <param name="workbook"></param>
        /// <param name="sheet"></param>
        public string CloneAndCreateSheet(HSSFWorkbook workbook, HSSFSheet sheet)
        {
            if (workbook == null || sheet == null)
            {
                return "";
            }
            HSSFSheet newsheet;
            int index = workbook.GetSheetIndex(sheet);
            newsheet = (HSSFSheet)sheet.Workbook.CloneSheet(index);
           
            //图片的问题暂时放一下,当复制到同一个workbook中的时候,填充完数据以后,图片显示不出来,暂时还没有找到好的方法解决

            return newsheet.SheetName;
        }

Sep 16, 2010 at 10:53 AM

This seems like you are copying a sheet within the same workbook, but the question was copying from workbook A to workbook B.  I never found a way to do this, and so abandoned using this product and instead we went with GemBox

Oct 6, 2010 at 12:24 PM

http://www.coderanch.com/t/420958/open-source/Copying-sheet-excel-file-another

just convert the sample to c#