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


C# Microsoft.Office.Interop.Excel.Application.Save方法代码示例

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


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

示例1: ExportExcel_CTCCByGroup


//.........这里部分代码省略.........
                       //cac tham so
                       int record_count = dtView.Count;
                       int record_mod = record_count;

                       string pos_begin1 = pos_column;
                       int pos_begin2 = pos_row;

                       object[,] Array_Record;
                       string Cell_Begin, Cell_End;

                       Cell_Begin = pos_begin1 + (pos_begin2).ToString();
                       Cell_End = MaxColumn + (record_count + pos_row - 1).ToString();
                       if (Show_Column == true)
                       {
                           Cell_End = MaxColumn + (record_mod + pos_row).ToString();
                       }
                       Array_Record = new object[record_mod, dt.Columns.Count];
                       for (int l = 0; l < record_mod; l++)
                       {
                           for (int m = 0; m < dt.Columns.Count; m++)
                           {
                               Array_Record[l, m] = dtView[l][m];
                           }
                           // SET MAU KHONG CHAM CONG
                           //if (Array_Record[l, 9].ToString()== "")
                           //{
                           //    chartRange = Sheet.get_Range("J" + l+pos_row, Type.Missing);
                           //    chartRange.Interior.Color = System.Drawing.Color.Blue.ToArgb();
                           //}
                           //if (Array_Record[l, 10].ToString() == "")
                           //{
                           //    chartRange = Sheet.get_Range("K" + l + pos_row, Type.Missing);
                           //    chartRange.Interior.Color = System.Drawing.Color.Blue.ToArgb();
                           //}
                       }
                       Sheet.get_Range(Cell_Begin, Cell_End).Value2 = Array_Record;
                       Sheet.get_Range(Cell_Begin, Cell_End).Borders.LineStyle = 1;

                       Sheet.Name = dtpb.Rows[ii]["DepartmentName"].ToString();
                       Sheet.Copy(Sheet);

                       // clrear txt
                       Array_Record = new object[record_mod, dt.Columns.Count];
                       for (int l = 0; l < record_mod; l++)
                           for (int m = 0; m < dt.Columns.Count; m++)
                           {
                               Array_Record[l, m] = "";
                           }
                       Sheet.get_Range(Cell_Begin, Cell_End).Value2 = Array_Record;
                       Sheet.get_Range(Cell_Begin, Cell_End).Borders.LineStyle = 0;
                        //Sheet.get_Range(Cell_Begin, Cell_End).Interior.Color = System.Drawing.Color.Transparent.ToArgb();
                       // end cler text in excel
                   }
               }
               // end for phong ban
               for (int iii = 1; iii < WorkBook.Worksheets.Count; iii++) // xóa số (2) o sheet name
               {
                   Microsoft.Office.Interop.Excel._Worksheet SheetName = (Microsoft.Office.Interop.Excel._Worksheet)WorkBook.Worksheets[iii];
                   string _sheetname = SheetName.Name;
                   _sheetname = _sheetname.Replace("(2)", "");
                   SheetName.Name = _sheetname;
               }
               //save file
               if (sfilename == "")
               {
                   ReportFile.AlertBeforeOverwriting = false;
                   ReportFile.DisplayAlerts = false;
                   ReportFile.Save(Type.Missing);
                   MessageBox.Show("Export Excel Successful !!!");
               }
               else
               {
                   //if (IsOpen)
                   //{
                   //    IsOpen = false;
                   //}
                   WorkBook.Save();
                   //  MessageBox.Show("Export Excel Successful !!!");
               }

               if (IsOpen)
               {
                   ReportFile.Visible = true;
                   ReportFile.UserControl = true;
               }
               //ReportFile.Quit();
               releaseObject(Sheet);
               releaseObject(WorkBook);
               releaseObject(ReportFile);
               //foreach (Process process in Process.GetProcessesByName("EXCEL"))
               //{
               //    process.Kill();
               //}
               }
               catch (Exception exx)
               {
               string Error = exx.ToString();

               }
        }
开发者ID:tayeumi,项目名称:HFC,代码行数:101,代码来源:ExportDataToExcel.cs

示例2: ExportExcel_CTCC


//.........这里部分代码省略.........

                   //Xuat cot mac dinh trong table neu Show_Column == true
                   if (Show_Column == true)
                   {
                       CreateColumnName(dt, Sheet, pos_row);
                       pos_begin2 = pos_row + 1;
                   }
                   object[,] Array_Record;
                   string Cell_Begin, Cell_End;

                       Cell_Begin = pos_begin1 + (pos_begin2).ToString();
                       Cell_End = MaxColumn + (record_count + pos_row - 1).ToString();
                       if (Show_Column == true)
                       {
                           Cell_End = MaxColumn + (record_mod + pos_row).ToString();
                       }
                       Array_Record = new object[record_mod, dt.Columns.Count];
                       for (int l = 0; l < record_mod; l++)
                           for (int m = 0; m < dt.Columns.Count; m++)
                           {
                               Array_Record[l, m] = dtView[l][m];
                           }
                       Sheet.get_Range(Cell_Begin, Cell_End).Value2 = Array_Record;
                       Sheet.get_Range(Cell_Begin, Cell_End).Borders.LineStyle = 1;

                   //for (int l = 0; l < record_mod; l++)
                   //        for (int m = 0; m < dt.Columns.Count; m++)
                   //        {
                   //            if (m == 9)
                   //            {
                   //                if (Array_Record[l, m]==DBNull.Value)
                   //                {
                   //                   Sheet.get_Range("J"+l).Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DarkOrange);
                   //                }
                   //            }
                   //        }

                   // copy sheet to new
                   //   Sheet.Copy(WorkBook.Sheets[0], WorkBook.Sheets[1]);
                   //Microsoft.Office.Interop.Excel._Worksheet Sheet2 = (Microsoft.Office.Interop.Excel._Worksheet)WorkBook.Worksheets[2];
                   Sheet.Name = dtpb.Rows[ii]["DepartmentName"].ToString();
                   Sheet.Copy(Sheet);

                   // clrear txt
                   Array_Record = new object[record_mod, dt.Columns.Count];
                   for (int l = 0; l < record_mod; l++)
                       for (int m = 0; m < dt.Columns.Count; m++)
                       {
                           Array_Record[l, m] = "";
                       }
                   Sheet.get_Range(Cell_Begin, Cell_End).Value2 = Array_Record;
                   Sheet.get_Range(Cell_Begin, Cell_End).Borders.LineStyle = 0;
                   // end cler text in excel
               }
               // end for phong ban

               for (int iii = 1; iii < WorkBook.Worksheets.Count; iii++) // xóa số (2) o sheet name
               {
                  Microsoft.Office.Interop.Excel._Worksheet SheetName= (Microsoft.Office.Interop.Excel._Worksheet)WorkBook.Worksheets[iii];
                  string _sheetname = SheetName.Name;
                  _sheetname = _sheetname.Replace("(2)", "");
                  SheetName.Name = _sheetname;
               }
                //save file
               if (sfilename == "")
               {
                   ReportFile.AlertBeforeOverwriting = false;
                   ReportFile.DisplayAlerts = false;
                   ReportFile.Save(Type.Missing);
                   MessageBox.Show("Export Excel Successful !!!");
               }
               else
               {
                   //if (IsOpen)
                   //{
                   //    IsOpen = false;
                   //}
                   WorkBook.Save();
                 //  MessageBox.Show("Export Excel Successful !!!");
               }

               if (IsOpen)
               {
                   ReportFile.Visible = true;
                   ReportFile.UserControl = true;
               }
               //ReportFile.Quit();
               releaseObject(Sheet);
               releaseObject(WorkBook);
               releaseObject(ReportFile);
               //foreach (Process process in Process.GetProcessesByName("EXCEL"))
               //{
               //    process.Kill();
               //}
               }
            catch (Exception ex)
            {
                Class.App.Log_Write(ex.Message);
            }
        }
开发者ID:tayeumi,项目名称:HFC,代码行数:101,代码来源:ExportDataToExcel.cs

示例3: ExportExcel


//.........这里部分代码省略.........
                string Cell_Begin, Cell_End;

                if (record_div == 0)    //case record_count<1000
                {
                    Cell_Begin = pos_begin1 + (pos_begin2).ToString();
                    Cell_End = MaxColumn + (record_mod + pos_row - 1).ToString();
                    if (Show_Column == true)
                    {
                        Cell_End = MaxColumn + (record_mod + pos_row).ToString();
                    }
                    Array_Record = new object[record_mod, dt.Columns.Count];
                    for (int l = 0; l < record_mod; l++)
                        for (int m = 0; m < dt.Columns.Count; m++)
                        {
                            Array_Record[l, m] = dt.Rows[l].ItemArray[m];
                        }
                    Sheet.get_Range(Cell_Begin, Cell_End).Value2 = Array_Record;
                    Sheet.get_Range(Cell_Begin, Cell_End).Borders.LineStyle = 1;
                }
                else    //case record_count>1000
                {
                    int pos_end = 1000 + pos_row;
                    int temp = 0;
                    Cell_Begin = pos_begin1 + pos_begin2.ToString();
                    Cell_End = MaxColumn + (pos_end).ToString();
                    for (int i = 0; i < record_div; i++)
                    {
                        Array_Record = new object[1000, dt.Columns.Count];
                        for (int k = temp, l = 0; k < temp + 1000; k++, l++)
                            for (int m = 0; m < dt.Columns.Count; m++)
                            {
                                Array_Record[l, m] = dt.Rows[k].ItemArray[m];
                            }
                        Sheet.get_Range(Cell_Begin, Cell_End).Value2 = Array_Record;
                        Sheet.get_Range(Cell_Begin, Cell_End).Borders.LineStyle = 1;
                        if (i < record_div - 1)
                        {
                            temp += 1000;
                            pos_end += 1000;
                            pos_begin2 += 1000;
                            Cell_Begin = pos_begin1 + pos_begin2.ToString();
                            Cell_End = MaxColumn + pos_end.ToString();
                        }
                    }
                    temp += 1000;
                    pos_end += record_mod;
                    pos_begin2 += 1000;
                    Cell_Begin = pos_begin1 + pos_begin2.ToString();
                    Cell_End = MaxColumn + (pos_end - 1).ToString();
                    if (Show_Column == true)
                    {
                        Cell_End = MaxColumn + pos_end.ToString();
                    }
                    Array_Record = new object[record_mod, dt.Columns.Count];

                    for (int l = 0; l < record_mod; l++)
                        for (int m = 0; m < dt.Columns.Count; m++)
                        {
                            Array_Record[l, m] = dt.Rows[temp + l].ItemArray[m];
                        }
                    Sheet.get_Range(Cell_Begin, Cell_End).Value2 = Array_Record;
                    Sheet.get_Range(Cell_Begin, Cell_End).Borders.LineStyle = 1;
                }
                //save file
                if (sfilename == "")
                {
                    ReportFile.AlertBeforeOverwriting = false;
                    ReportFile.DisplayAlerts = false;
                    ReportFile.Save(Type.Missing);
                    MessageBox.Show("Export Excel Successful !!!");
                }
                else
                {
                    //if (IsOpen)
                    //{
                    //    IsOpen = false;
                    //}
                    WorkBook.Save();
                    MessageBox.Show("Export Excel Successful !!!");
                }

                if (IsOpen)
                {
                    ReportFile.Visible = true;
                    ReportFile.UserControl = true;
                }
                //ReportFile.Quit();
                releaseObject(Sheet);
                releaseObject(WorkBook);
                releaseObject(ReportFile);
                //foreach (Process process in Process.GetProcessesByName("EXCEL"))
                //{
                //    process.Kill();
                //}
            }
            catch (Exception exx)
            {
                string Error = exx.ToString();
            }
        }
开发者ID:tayeumi,项目名称:HFC,代码行数:101,代码来源:ExportDataToExcel.cs

示例4: SaveDataTableToExcel

 public static void SaveDataTableToExcel(DataTable excelTable, string filePath)
 {
     Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
     try
     {
         app.Visible = false;
         Microsoft.Office.Interop.Excel.Workbook wBook = app.Workbooks.Add(true);
         Microsoft.Office.Interop.Excel.Worksheet wSheet = wBook.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
         if (excelTable.Rows.Count > 0)
         {
             int row = 0;
             row = excelTable.Rows.Count;
             int col = excelTable.Columns.Count;
             for (int i = 0; i < row; i++)
             {
                 for (int j = 0; j < col; j++)
                 {
                     string str = excelTable.Rows[i][j].ToString();
                     wSheet.Cells[i + 2, j + 1] = str;
                 }
             }
         }
         int size = excelTable.Columns.Count;
         for (int i = 0; i < size; i++)
         {
             wSheet.Cells[1, 1 + i] = excelTable.Columns[i].ColumnName;
         }
         //设置禁止弹出保存和覆盖的询问提示框  
         app.DisplayAlerts = false;
         app.AlertBeforeOverwriting = false;
         //保存工作簿   
         wBook.Save();
         //保存excel文件   
         app.Save(filePath);
         app.SaveWorkspace(filePath);
         app.Quit();
         app = null;
     }
     catch
     {
         throw;
     }
 }
开发者ID:abc52406,项目名称:PbTool,代码行数:43,代码来源:ExcelHelper.cs


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