Beispiel #1
0
        public static Book Open(string path)
        {
            Workbook _workbook = TableReaderApp.GetExcelApp().Workbooks.Open(path,
                                                                             Type.Missing, true, Type.Missing, Type.Missing,
                                                                             Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                             Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                             Type.Missing, Type.Missing);

            int    pos      = path.LastIndexOf("\\") + 1;
            Book   result   = new Book(_workbook);
            string fileName = path.Substring(pos, path.Length - pos);
            int    pset     = fileName.LastIndexOf(".");

            result.Name = fileName.Substring(0, pset);

            int count = _workbook.Worksheets.Count;

            for (int i = 1; i <= count; i++)
            {
                Worksheet sheet = (Worksheet)_workbook.Worksheets[i];
                result.Pages.Add(sheet.Name, new Page(sheet));
            }

            return(result);
        }
Beispiel #2
0
        public static Book Create(List <string> pageNames)
        {
            Workbook _workbook = TableReaderApp.GetExcelApp().Workbooks.Add(Type.Missing);
            int      count     = _workbook.Worksheets.Count;

            for (int i = count; i > 1; i--)
            {
                ((Worksheet)_workbook.Worksheets[i]).Delete();
            }

            ((Worksheet)_workbook.Worksheets[1]).Name = pageNames[0];
            Book result = new Book(_workbook);

            result.Pages.Add(pageNames[0], new Page((Worksheet)_workbook.Worksheets[1], _workbook.Styles));

            for (int i = 1; i < pageNames.Count; i++)
            {
                result.AddNewPage(pageNames[i]);
            }

            return(result);
        }