Ejemplo n.º 1
0
        /// <summary>
        /// Create an Excel spreadsheet and add all the tables in the dataset to it.
        /// </summary>
        /// <param name="ds">A .NET DataSet</param>
        public void CreateExcel(DataSet ds)
        {
            _log.InfoFormat("enter {0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            Workbook workbook = new Workbook();

            //this initializes the aspose license for us!
            ExcelUtilities.createNewWorkbook(1, ref workbook);

            _log.Debug("creating db info worksheet");
            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Name = WorksheetNames.Default.dbInfo;
            ImportTable(ds.Tables["dbInfo1"], worksheet, 1, 1);
            ImportTable(ds.Tables["dbInfo2"], worksheet, 3 + ds.Tables["dbInfo1"].Rows.Count, 1);
            ImportTable(ds.Tables["dbInfo3"], worksheet, 5 + ds.Tables["dbInfo2"].Rows.Count + ds.Tables["dbInfo1"].Rows.Count, 1);
            worksheet.Cells.Columns[2].Width = 75; //fix auto size issue
            TrimRowsAndColumns(worksheet);         //fix trim issue for row/column padding to make utility method call work

            _log.Debug("created misc config worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.siqConfig);
            ImportTable(ds.Tables["siqConfig1"], worksheet, 1, 1);
            ImportTable(ds.Tables["siqConfig2"], worksheet, 3 + ds.Tables["siqConfig1"].Rows.Count, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating license worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.license);
            ImportTable(ds.Tables["license"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating core service worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.coreServices);
            ImportTable(ds.Tables["installServer"], worksheet, 1, 1);
            ImportTable(ds.Tables["installService"], worksheet, 3 + ds.Tables["installServer"].Rows.Count, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating idc worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.idc);
            ImportTable(ds.Tables["idc"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating wpc worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.wpc);
            ImportTable(ds.Tables["wpc"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating apps worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.apps);
            ImportTable(ds.Tables["apps"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating appConfigs worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.appConfigs);
            ImportTable(ds.Tables["appConfigs"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating tasks worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.tasks);
            ImportTable(ds.Tables["tasks"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating taskResults worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.taskResults);
            ImportTable(ds.Tables["taskResults"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating health worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.healthCenter);
            ImportTable(ds.Tables["healthCenter"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("creating users worksheet");
            worksheet = workbook.Worksheets.Add(WorksheetNames.Default.users);
            ImportTable(ds.Tables["users"], worksheet, 1, 1);
            TrimRowsAndColumns(worksheet);

            _log.Debug("saving workbook");
            workbook.Save(GetExcelFileName(), SaveFormat.Xlsx);

            _log.InfoFormat("exit {0}", System.Reflection.MethodBase.GetCurrentMethod().Name);
        }