Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

TblProc: OpenOffice Calc and Excel

, 29 Jan 2009 CDDL
OpenOffice Calc and Excel
TblProc_demo.zip
TblProcBin
Interop.Excel.dll
Interop.Microsoft.Office.Core.dll
TblProc.dll
Test.exe
TblProc_src.zip
TblProcSrc
OO3.0_dlls
cli_basetypes.dll
cli_cppuhelper.dll
cli_oootypes.dll
cli_uno.dll
cli_ure.dll
cli_uretypes.dll
TblProc
Properties
TblProc.suo
Test
Properties
DataSources
DataClass.datasource
Settings.settings
using System;
using System.Collections.Generic;
using System.Text;
using MSExcel = Excel;

/********************************************************************************
* Copyright : Alexander Sazonov 2009                                           //
*                                                                              //
* Email : sazon666@mail.ru                                                     //
*         sazon@freemail.ru                                                    // 
*                                                                              //
* This code may be used in any way you desire. This                            //
* file may be redistributed by any means PROVIDING it is                       //
* not sold for profit without the authors written consent, and                 //
* providing that this notice and the authors name is included.                 //
*                                                                              //
* This file is provided 'as is' with no expressed or implied warranty.         //
* The author accepts no liability if it causes any damage to your computer.    //
*                                                                              //
* Expect Bugs.                                                                 //
* Please let me know of any bugs/mods/improvements.                            //
* and I will try to fix/incorporate them into this file.                       //
* thx Amar Chaudhary for disclaimer text ;-)                                   //
* Enjoy!                                                                       //
*                                                                              //
*/
/////////////////////////////////////////////////////////////////////////////////

//An Excel table processor wrapper class. represents an xls document

namespace SA.TblProc.Excel
{
    public class ExcelApp : TableProcessor
    {
        private MSExcel.Workbook _wbook;
        private List<ExcelSheet> _pages = new List<ExcelSheet>();

        public MSExcel.Workbook Workbook
        {
            get { return _wbook; }
        }

        public ExcelApp() : this(null, 1) { }
        public ExcelApp(string firstPageName) : this(firstPageName, 1) { }
        public ExcelApp(string firstPageName, int firstPageStartRow)
        {
            MSExcel.Application xls = new MSExcel.Application();
            _wbook = xls.Workbooks.Add(MSExcel.XlWBATemplate.xlWBATWorksheet);
            MSExcel.Worksheet sheet = (MSExcel.Worksheet)(_wbook.Worksheets.get_Item(1));
            if (firstPageName != null) sheet.Name = firstPageName;
            ExcelSheet page = new ExcelSheet(sheet, firstPageStartRow);
            _pages.Add(page);
        }
        public ExcelApp(MSExcel.Workbook wbook)
        {
            this._wbook = wbook;
            for (int i = 0; i < wbook.Worksheets.Count; i++)
            {
                ExcelSheet page = new ExcelSheet((MSExcel.Worksheet)wbook.Worksheets[i], 1);
                _pages.Add(page);
            }

        }
        public override TableSheet FirstPage
        {
            get
            {
                return FirstExcelPage;
            }
        }
        public ExcelSheet FirstExcelPage
        {
            get
            {
                return _pages[0];
            }
        }
        public override TableSheet LastPage
        {
            get
            {
                return LastExcelPage;
            }
        }
        public ExcelSheet LastExcelPage
        {
            get
            {
                return _pages[_pages.Count - 1];
            }
        }

        public override TableSheet CreateNextPage(string name, int startRow)
        {
            return CreateNextExcelPage(name, startRow);
        }

        public ExcelSheet CreateNextExcelPage(string name, int startRow)
        {
            MSExcel.Worksheet prevSheet = _pages[_pages.Count - 1].Worksheet;
            MSExcel.Sheets sheets = _wbook.Worksheets;
            MSExcel.Worksheet newSheet = (MSExcel.Worksheet)sheets.Add(System.Type.Missing,
                prevSheet, 1, prevSheet.Type);
            newSheet.Name = name;
            ExcelSheet ret = new ExcelSheet(newSheet, startRow);
            _pages.Add(ret);
            return ret;
        }
        public override TableSheet this[int idx]
        {
            get
            {
                return _pages[idx];
            }
        }

        public override bool Visible
        {
            set
            {
                _wbook.Application.Visible = value;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)

Share

About the Author

Aleksandr Sazonov
Software Developer (Senior)
Russian Federation Russian Federation
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 29 Jan 2009
Article Copyright 2007 by Aleksandr Sazonov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid