当前位置: 首页>>代码示例>>C#>>正文


C# IWorkbook.Save方法代码示例

本文整理汇总了C#中IWorkbook.Save方法的典型用法代码示例。如果您正苦于以下问题:C# IWorkbook.Save方法的具体用法?C# IWorkbook.Save怎么用?C# IWorkbook.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWorkbook的用法示例。


在下文中一共展示了IWorkbook.Save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessWorkbook

        /// <summary>
        /// Adds DES worksheet in workbook passed and fills it with Data, provided in DataView, in DES format.
        /// </summary>
        private void ProcessWorkbook(bool singleWorkbook, ref IWorkbook DESWorkbook, DataView filteredDataView, int IUCounter, string xlsFileNameWPath, string languageFileNameWPath)
        {
            IWorksheet DESWorsheet;
            string IndicatorUnitWorkbookName = string.Empty;    // Workbook name for each Indicator + Unit
            int SheetCounter = 1;

            List<DataTable> TableLists = GetDataTableListInChunk(filteredDataView.ToTable(), 65500);

            // Checking if singleWorkbook = false then save each worksheet in seperate workbook
            if (singleWorkbook == false)
            {
                foreach (DataTable ChunkTable in TableLists)
                {
                    DataView TempView = ChunkTable.DefaultView;
                    //// Update Sector , Class in DataView
                    //DIExport.AddSectorClassInDataView(ref TempView, dBConnection, dBQueries, IndicatorNId, UnitNId);

                    // Set Indicator, Unit Name for progress bar event, and raise Progress_Increment event
                    this.RaiseProcessIndicatorUnitInfo(TempView[0][Indicator.IndicatorName].ToString(), TempView[0][Unit.UnitName].ToString(), filteredDataView.Count);
                    // Get a blank DES workbook from resource file, only at first time.
                    if (SheetCounter == 1)
                    {
                        IndicatorUnitWorkbookName = this.SetWorkbookName(TempView[0][Indicator.IndicatorName].ToString(), TempView[0][Unit.UnitName].ToString());

                        // Get a blank DES workbook from resource file, and save it as specified file.
                        ExportDES.GetWorkbookFromResourceFile(WorkbookType.DataEntrySpreadsheet, Path.Combine(Path.GetDirectoryName(xlsFileNameWPath), IndicatorUnitWorkbookName + ".xls"));

                        // Create Workbook instance from same file.
                        DESWorkbook = SpreadsheetGear.Factory.GetWorkbook(Path.Combine(Path.GetDirectoryName(xlsFileNameWPath), IndicatorUnitWorkbookName + ".xls"));

                        DESWorkbook.Worksheets[0].CopyBefore(DESWorkbook.Sheets[DESWorkbook.Worksheets.Count - 1]);
                        DESWorkbook.Worksheets[DESWorkbook.Worksheets.Count - 1].Visible = SheetVisibility.Hidden;

                        DESWorsheet = DESWorkbook.Worksheets[0];
                        DESWorsheet.Name = "Data " + "1" + Convert.ToString(TableLists.Count > 1 ? "_" + SheetCounter.ToString() : String.Empty);
                    }
                    else
                    {

                        // Copy default worksheet before itself. (i.e. Default worksheet copying itself into another new worksheet)
                        // hence, newly created worksheet will always be at second last position.
                        DESWorkbook.Worksheets[DESWorkbook.Worksheets.Count - 1].CopyBefore(DESWorkbook.Sheets[DESWorkbook.Worksheets.Count - 1]);

                        // Assign newly created workbook which is present at second last position.
                        DESWorsheet = DESWorkbook.Worksheets[DESWorkbook.Worksheets.Count - 2];
                        DESWorsheet.Visible = SheetVisibility.Visible;
                        // Rename worksheet name to "Data C"  (C - SheetNumber)
                        DESWorsheet.Name = "Data " + "1" + "_" + SheetCounter.ToString();

                    }
                    // Fill worksheet with Data in DES format, passing worksheet reference to ExportDES class method
                    ExportDES.ExportDESData(DESWorsheet, TempView, languageFileNameWPath);

                    SheetCounter++;
                }

                // Save workbook
                DESWorkbook.Save();

            }
            else
            {
                foreach (DataTable ChunkTable in TableLists)
                {
                    DataView TempView = ChunkTable.DefaultView;
                    //// Update Sector , Class in DataView
                    //DIExport.AddSectorClassInDataView(ref TempView, dBConnection, dBQueries, IndicatorNId, UnitNId);

                    // Set Indicator, Unit Name for progress bar event, and raise Progress_Increment event
                    this.RaiseProcessIndicatorUnitInfo(TempView[0][Indicator.IndicatorName].ToString(), TempView[0][Unit.UnitName].ToString(), filteredDataView.Count);
                    // Get a blank DES workbook from resource file, only at first time.
                    if (IUCounter == 1)
                    {
                        ExportDES.GetWorkbookFromResourceFile(WorkbookType.DataEntrySpreadsheet, xlsFileNameWPath);

                        DESWorkbook = SpreadsheetGear.Factory.GetWorkbook(xlsFileNameWPath);
                    }
                    // Copy default worksheet before itself. (i.e. Default worksheet copying itself into another new worksheet)
                    // hence, newly created worksheet will always be at second last position.
                    DESWorkbook.Worksheets[DESWorkbook.Worksheets.Count - 1].CopyBefore(DESWorkbook.Sheets[DESWorkbook.Worksheets.Count - 1]);

                    // Assign newly created workbook which is present at second last position.
                    DESWorsheet = DESWorkbook.Worksheets[DESWorkbook.Worksheets.Count - 2];

                    // Rename worksheet name to "Data C"  (C - SheetNumber)
                    DESWorsheet.Name = "Data " + IUCounter.ToString() + Convert.ToString(TableLists.Count > 1 ? "_" + SheetCounter.ToString() : String.Empty);

                    // Fill worksheet with Data in DES format, passing worksheet reference to ExportDES class method
                    ExportDES.ExportDESData(DESWorsheet, ChunkTable.DefaultView, languageFileNameWPath);

                    SheetCounter++;
                }

            }
        }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:98,代码来源:DIExport.cs

示例2: Save

 /// <summary>
 /// To save opened workbook
 /// </summary>
 /// <param name="workbook"></param>
 internal static void Save(IWorkbook workbook)
 {
     if (workbook != null)
     {
         try
         {
             for (int i = 0; i < 5; i++)
             {
                 try
                 {
                     workbook.Save();
                     break;
                 }
                 catch (Exception)
                 {}
             }
         }
         catch (Exception ex)
         {
             new ApplicationException(ex.ToString());
         }
     }
 }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:27,代码来源:ExcelHelper.cs

示例3: RenameWorkSheet

 ///// <summary>
 ///// 
 ///// </summary>
 ///// <param name="workbook"></param>
 ///// <param name="sheetIndex"></param>
 ///// <param name="rowIndex"></param>
 ///// <param name="colIndex"></param>
 ///// <param name="ColumnWidth"></param>
 //internal static void SetColumnWidth(IWorkbook workbook, int sheetIndex,int startRowIndex,int startColIndex,int endRowIndex,int endColIndex,double ColumnWidth)
 //{
 //    try
 //    {
 //        // Get a worksheet reference.
 //        SpreadsheetGear.IWorksheet Worksheet = workbook.Worksheets[sheetIndex];
 //        if (Worksheet != null)
 //        {
 //            Worksheet.Cells[startRowIndex, startColIndex, endRowIndex, endColIndex].Width = ColumnWidth;
 //        }
 //    }
 //    catch (Exception ex)
 //    {
 //        //                new ApplicationException(ex.ToString());
 //    }
 //}
 internal static void RenameWorkSheet(IWorkbook workbook, int sheetIndex, string sheetName)
 {
     try
     {
         // Get a worksheet reference.
         SpreadsheetGear.IWorksheet Worksheet = workbook.Worksheets[sheetIndex];
         if (Worksheet != null)
         {
             Worksheet.Name = sheetName;
             workbook.Save();
         }
     }
     catch (Exception ex)
     {
         //                new ApplicationException(ex.ToString());
     }
 }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:41,代码来源:ExcelHelper.cs

示例4: Save

 /// <summary>
 /// To save opened workbook
 /// </summary>
 /// <param name="workbook"></param>
 internal static void Save(IWorkbook workbook)
 {
     if (workbook != null)
     {
         try
         {
             for (int i = 0; i < 5; i++)
             {
                 try
                 {
                     workbook.Save();
                     break;
                 }
                 catch (Exception)
                 {}
             }
         }
         catch (Exception ex)
         {
             ExceptionFacade.ThrowException(ex);
         }
     }
 }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:27,代码来源:ExcelHelper.cs

示例5: RenameWorkSheet

        /// <summary>
        /// Renames the active worksheet
        /// </summary>
        /// <param name="workbook">Active workbook</param>
        /// <param name="oldSheetName">old worksheet name</param>
        /// <param name="newSheetName">new worksheet name</param>
        internal static void RenameWorkSheet(IWorkbook workbook, string oldSheetName, string newSheetName)
        {
            try
            {
                // Get a worksheet reference.
                SpreadsheetGear.IWorksheet Worksheet = workbook.Worksheets[oldSheetName];

                if (Worksheet != null)
                {
                    Worksheet.Name = newSheetName;
                    workbook.Save();
                }
            }
            catch (Exception ex)
            {
                //                ExceptionFacade.ThrowException(ex);
            }
        }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:24,代码来源:ExcelHelper.cs

示例6: Save

    /// <summary>
    /// To save opened workbook
    /// </summary>
    /// <param name="workbook"></param>
    internal static void Save(IWorkbook workbook)
    {
        try
        {
            workbook.Save();
        }
        catch (Exception ex)
        {

            //                 throw ex;
        }
    }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:16,代码来源:ExcelHelper.cs


注:本文中的IWorkbook.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。