示例#1
0
        public void Convert(string[] originalFiles)
        {
            try
            {
                Logger.WriteLine(Environment.NewLine + "Creating new book at: " + m_outputDirectory + Environment.NewLine);
                var book = NPOIUtility.CreateNewBook(m_outputDirectory);

                int fileCount = originalFiles.Length;
                Logger.WriteLine("Start Processing...{0} files", fileCount);
                for (int i = 0; i < fileCount; ++i)
                {
                    Logger.WriteLine("...processing file [{0}/{1}]", i + 1, fileCount);
                    CopySheet(book as HSSFWorkbook, i, originalFiles[i]);
                }

                using (var fs = File.Create(m_outputDirectory))
                {
                    book.Write(fs);
                    book.Close();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine(ex.Message);
            }
        }
示例#2
0
        private void CopySheet(HSSFWorkbook book, int index, string loadFilePath)
        {
            IWorkbook loadedBook = NPOIUtility.LoadBook(loadFilePath);

            if (loadedBook == null)
            {
                return;
            }

            ((HSSFSheet)loadedBook.GetSheetAt(0)).CopyTo(book, loadedBook.GetSheetName(0), true, true);
        }