コード例 #1
0
ファイル: Program.cs プロジェクト: zhq229485/npoi
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World! Please Wait while processing...");
            //Excel worksheet combine example
            //Note: This example does not check for duplicate sheet names. Your test files should have different sheet names.

            IWorkbook book1 = new HSSFWorkbook(new FileStream("file1.xls", FileMode.Open));
            /*IWorkbook book2 = new HSSFWorkbook(new FileStream("file2.xls", FileMode.Open));*/
            IWorkbook product = new HSSFWorkbook();

            for (int i = 0; i < book1.NumberOfSheets; i++)
            {
                ISheet sheet1 = book1.GetSheetAt(i);
                sheet1.CopyTo(product, sheet1.SheetName, true, true);
            }

            /* something wrong with copying pictures in file2.xls. We need to figure out
             * for (int j = 0; j < book2.NumberOfSheets; j++)
             *  {
             *      ISheet sheet2 = book2.GetSheetAt(j);
             *      sheet2.CopyTo(product, sheet2.SheetName, true, true);
             *  }
             */
            product.Write(new FileStream("test.xls", FileMode.Create, FileAccess.ReadWrite));
        }
コード例 #2
0
        public void CopiarHoja(string archivo, int intHoja, string NombreHoja)
        {
            ISheet    sheet     = null;
            IWorkbook hssfwb    = null;
            FileInfo  fi        = new FileInfo(archivo);
            string    extension = fi.Extension;

            using (FileStream file = new FileStream(@archivo, FileMode.Open, FileAccess.Read))
            {
                //hssfwb = new HSSFWorkbook(file);
                if (extension == ".xlsx")
                {
                    hssfwb = new XSSFWorkbook(file);
                }

                else if (extension == ".xls")
                {
                    hssfwb = new HSSFWorkbook(file);
                }
            }
            sheet = hssfwb.GetSheetAt(intHoja);
            sheet.CopyTo(hssfwb, $"{NombreHoja}", true, true);

            using (FileStream fs = new FileStream(@archivo, FileMode.Create, FileAccess.Write))
            {
                hssfwb.Write(fs);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: nissl-lab/npoi-examples
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World! Please Wait while processing...");
            //Excel worksheet combine example
            //Note: This example does not check for duplicate sheet names. Your test files should have different sheet names.

            IWorkbook book1   = new XSSFWorkbook(new FileStream("file1.xlsx", FileMode.Open));
            IWorkbook book2   = new XSSFWorkbook(new FileStream("file2.xlsx", FileMode.Open));
            IWorkbook product = new XSSFWorkbook();

            for (int i = 0; i < book1.NumberOfSheets; i++)
            {
                ISheet sheet1 = book1.GetSheetAt(i);
                sheet1.CopyTo(product, sheet1.SheetName, true, true);
            }

            for (int j = 0; j < book2.NumberOfSheets; j++)
            {
                ISheet sheet2 = book2.GetSheetAt(j);
                sheet2.CopyTo(product, sheet2.SheetName, true, true);
            }

            using (FileStream sw = File.Create("test.xlsx"))
            {
                product.Write(sw);
            }
        }