Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- //using System.Linq;
- using System.Text;
- using Microsoft.Office.Interop.Excel;
- using System.Threading;
- using System.Globalization;
- using Office = Microsoft.Office.Core;
- using Microsoft.Office.Core;
- namespace TestExcel
- {
- class Program
- {
- static void Main(string[] args)
- {
- Application xlApp = null;
- Workbook xlWorkBook = null;
- Workbook xlWorkBookChild = null;
- Workbooks xlWorkBooks = null;
- Worksheet xlWorkSheet = null;
- Sheets xlSheetChild;
- List<string> listaFicheiros = new List<string>();
- LanguageSettings xpto2;
- try
- {
- xlApp = new Application();
- Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
- xlWorkBook = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
- listaFicheiros.Add(@"\\filePath\file.xls");
- listaFicheiros.Add(@"\\filePath\file2.xls");
- foreach (string fileToParse in listaFicheiros)
- {
- xlWorkBookChild = xlApp.Workbooks.Open(fileToParse, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
- Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
- xlSheetChild = xlWorkBookChild.Sheets;
- if (fileToParse.Contains("MIS_PPP_ALL"))
- {
- xlWorkBook.set_Colors(Type.Missing, xlWorkBookChild.get_Colors(Type.Missing));
- }
- foreach (Worksheet xlWorkSheetChild in xlSheetChild)
- {
- // Get the last sheet
- xlWorkSheet = (Worksheet)xlWorkBook.Worksheets[xlWorkBook.Worksheets.Count];
- //xlWorkBook.Worksheets.Add(Type.Missing, xlWorkSheet);
- xlWorkSheetChild.Copy(Type.Missing, xlWorkSheet);
- }
- //xlWorkBook.set_Colors(Type.Missing, xlWorkBookChild.get_Colors(Type.Missing));
- xlWorkBookChild.Close();
- }
- //Microsoft.Office.Interop.Excel.Workbook _ColorsType c =
- //xlWorkBook.Colors = Workbook_ColorsType.Colors;
- xlWorkBook.SaveAs(@"C:\Users\tiago.palhota\Desktop\Excel Testing\tiago", XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
- xlWorkBook.Close();
- xlApp.Quit();
- //Console.ReadLine();
- }
- catch (Exception ex)
- {
- throw;
- }
- finally
- {
- xlApp.Quit();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement