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


C# Workbook.SaveAs方法代码示例

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


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

示例1: ToExcel

 /// <summary>
 /// DataTable导出EXCEL文件
 /// </summary>
 /// <param name="dt">DataTable</param>
 public void ToExcel(System.Data.DataTable dt) {
     if (xlsBook.IsNotNull()) xlsBook.Close();
     xlsBook = xlsApp.Workbooks.Add(true);
     toExcel(dt, 1);
     (xlsBook.Worksheets.get_Item(2) as Worksheet).Delete();
     FileDirectory.FileDelete(fileName);
     xlsBook.SaveAs(fileName, 56, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
 }
开发者ID:pczy,项目名称:Pub.Class,代码行数:12,代码来源:Excel11Writer.cs

示例2: SaveFile

 private static string SaveFile(string dir, Workbook xlWorkBook)
 {
     if (dir == null || dir == String.Empty)
     {
         dir = Directory.GetCurrentDirectory();
     }
     xlWorkBook.SaveAs(String.Format("{0}\\data.xls", dir), XlFileFormat.xlWorkbookNormal);
     return dir;
 }
开发者ID:mgevers-vintageSoftware,项目名称:MultiCorrelation,代码行数:9,代码来源:CorrelationCalc.cs

示例3: ExcelHandler

 public ExcelHandler(string filename, string url)
 {
     xlApp = new Microsoft.Office.Interop.Excel.Application();
     if (xlApp == null)
     {
         isOK = false;
         MessageBox.Show("Microsoft Excel не установлен или установлен некорректно");
         System.Windows.Forms.Application.Exit();
     }
     else
     {
         isOK = true;
         xlWorkBook = xlApp.Workbooks.Open(filename);
         xlWorkBook.SaveAs(filename);
         linkurl = url;
     }
 }
开发者ID:Witmaster,项目名称:LinkChecker,代码行数:17,代码来源:ExcelHandler.cs

示例4: GenerateExcelWithHeaderForPdf

        public void GenerateExcelWithHeaderForPdf(DataSet receiveDS, string filePath, int rowcout, string companyName, string companyAddress, int columnScape, bool istotal, int itemPerPage)
        {
            ds = receiveDS;
            strFileName = filePath;
            try
            {
                application = new Application();
                application.Visible = false;//true;
                application.DisplayAlerts = false;

                workbooks = application.Workbooks;
                workbook = (Workbook)application.Workbooks.Add(1);
                workbook.SaveAs(strFileName, XlFileFormat.xlWorkbookNormal, null, null, false, false,
                                XlSaveAsAccessMode.xlExclusive, false, false, null, null, false);

                range = ((Worksheet)workbook.ActiveSheet).get_Range("A1", "AZ1");
                range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

                Worksheet XLsheet = ((Worksheet)workbook.ActiveSheet);

                int excelSheetRow = this.WriteDataToTheSpecifiedRangeForPdf(ds.Tables[0], range, rowcout, itemPerPage, XLsheet, rowcout, companyName, columnScape);

                //if (istotal)
                //{

                //    var colCount = ds.Tables[0].Columns.Count;
                //    var dataRowCount = ds.Tables[0].Rows.Count;
                //    var headerRangeTotal = XLsheet.Range[XLsheet.Cells[excelSheetRow + 1, 1], XLsheet.Cells[excelSheetRow + 1, columnScape]];
                //    headerRangeTotal[1, 1] = "Total";
                //    headerRangeTotal.Font.Bold = true;
                //    headerRangeTotal.Font.Size = 12;
                //    headerRangeTotal.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.ColorTranslator.FromHtml("#CC99FF"));
                //    headerRangeTotal.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
                //    headerRangeTotal.Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Black);
                //    headerRangeTotal.Merge(Type.Missing);
                //    headerRangeTotal.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                //    //int i = columnScape - 1;

                //    for (int i = 0; i < colCount - columnScape; i++)
                //    {

                //        //var rangeTotal = XLsheet.Range[XLsheet.Cells[rowcout + dataRowCount + 1, i + columnScape + 1], XLsheet.Cells[rowcout + dataRowCount + 1, i + columnScape + 1]];
                //        var rangeTotal = XLsheet.Range[XLsheet.Cells[excelSheetRow + 1, i + columnScape + 1], XLsheet.Cells[excelSheetRow + 1, i + columnScape + 1]];
                //        string startColumnLetter = ExcelColumnLetter(i + columnScape);
                //        string endColumnLetter = ExcelColumnLetter(i + columnScape);
                //        rangeTotal[1, 1] = "=SUM(" + startColumnLetter + "" + (rowcout + 1) + ":" + endColumnLetter + "" + (rowcout + dataRowCount) + ")";
                //        rangeTotal[1, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.ColorTranslator.FromHtml("#CC99FF"));
                //        rangeTotal[1, 1].Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
                //        rangeTotal[1, 1].Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Black);

                //    }
                //}

                range = ((Worksheet)workbook.ActiveSheet).get_Range("A1", "AZ1");
                range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                XLsheet.PageSetup.PrintTitleRows = "$1:$6";
                XLsheet.Columns.AutoFit();

                XLsheet.Name = ds.Tables[0].TableName;
                workbook.Save();

            }
            catch (Exception exp)
            {

                throw exp;
            }
            finally
            {
                DisposeExcelObject();
            }
        }
开发者ID:mehedicse,项目名称:formiginationNET,代码行数:72,代码来源:AzExportToExcel.cs

示例5: GenerateExcelWithHeader

        public void GenerateExcelWithHeader(DataSet receiveDS, string filePath, int rowcout, string companyName, string companyAddress, int columnScape, bool istotal, DateTime salaryMonth)
        {
            ds = receiveDS;
            strFileName = filePath;
            try
            {
                application = new Application();
                application.Visible = false;//true;
                application.DisplayAlerts = false;

                workbooks = application.Workbooks;
                workbook = (Workbook)application.Workbooks.Add(1);
                workbook.SaveAs(strFileName, XlFileFormat.xlWorkbookNormal, null, null, false, false,
                                XlSaveAsAccessMode.xlExclusive, false, false, null, null, false);

                range = ((Worksheet)workbook.ActiveSheet).get_Range("A1", "AZ1");
                range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                //range = worksheet.Cells;

                Worksheet XLsheet = ((Worksheet)workbook.ActiveSheet);
                #region Main Header

                // if (companyName != "")
                //{
                var headerRange1 = XLsheet.Range[XLsheet.Cells[1, 1], XLsheet.Cells[rowcout - 2, 6]];
                //headerRange1[1, 1] = companyName;
                headerRange1.Font.Bold = true;
                headerRange1.Font.Size = 16;
                //headerRange1.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.ColorTranslator.FromHtml("#CC99FF"));
                //headerRange1.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
                //headerRange1.Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Black);
                headerRange1.Merge(Type.Missing);
                headerRange1.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                //var picPath = "G:\\Project\\Asp.Net\\Azolution\\Empress_4_0_0\\Empress_3_0_0\\Images\\" + "report-logo.png";
                string picPath = System.Web.HttpContext.Current.Server.MapPath("../Images/report-logo.png");
                object missing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Excel.Range picPosition = headerRange1;//GetPicturePosition(); // retrieve the range for picture insert
                Microsoft.Office.Interop.Excel.Pictures p = XLsheet.Pictures(missing) as Microsoft.Office.Interop.Excel.Pictures;
                Microsoft.Office.Interop.Excel.Picture pic = null;
                pic = p.Insert(picPath, missing);
                pic.Left = Convert.ToDouble(picPosition.Left);
                pic.Top = picPosition.Top;

                //  }
                if (companyName != "")
                {
                    var headerRange2 = XLsheet.Range[XLsheet.Cells[rowcout - 3, 7], XLsheet.Cells[rowcout - 3, 14]];
                    headerRange2[1, 1] = companyName;//companyAddress;
                    headerRange2.Font.Bold = true;
                    headerRange2.Font.Size = 12;
                    //headerRange2.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.ColorTranslator.FromHtml("#CC99FF"));
                    //headerRange2.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
                    //headerRange2.Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Black);
                    headerRange2.Merge(Type.Missing);
                    headerRange2.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                }
               // if (companyName != "")
               // {
                    var headerRange3 = XLsheet.Range[XLsheet.Cells[rowcout - 1, 1], XLsheet.Cells[rowcout - 1, 6]];
                    headerRange3[1, 1] = "Salary Control Register for the Month of " + salaryMonth.ToString("MMMM-yyyy");//companyAddress;
                    headerRange3.Font.Bold = true;
                    headerRange3.Font.Size = 12;
                    headerRange3.Merge(Type.Missing);
                    headerRange3.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;
                //}
                //var headerRang = XLsheet.get_Range(XLsheet.Cells[1, 1], XLsheet.Cells[1, 43]);

                #endregion

                #region Print DateTime

                //var headerRangeSystem = XLsheet.Range[XLsheet.Cells[rowcout - 1, ds.Tables[0].Columns.Count - 4], XLsheet.Cells[rowcout - 1, ds.Tables[0].Columns.Count]];
                //headerRangeSystem[1, 1] = "Print From Rapid 2.0";
                //headerRangeSystem.Font.Bold = true;
                //headerRangeSystem.Font.Size = 10;
                //headerRangeSystem.Merge(Type.Missing);
                //headerRangeSystem.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

                //var headerRangeDateTimeVal = XLsheet.Range[XLsheet.Cells[rowcout - 2, ds.Tables[0].Columns.Count - 4], XLsheet.Cells[rowcout - 2, ds.Tables[0].Columns.Count]];
                //headerRangeDateTimeVal[1, 1] = "Print Date & Time : " + DateTime.Now.ToString("MMMM dd, yyyy") + DateTime.Now.ToString("h:mm tt");//+ DateTime.Now.ToString("d-MMM-yyyy HH.mm.ss tt", CultureInfo.InvariantCulture);//DateTime.Now.ToString("dd MMM yyyy hh:mm:ss");//companyAddress;
                //headerRangeDateTimeVal.Font.Bold = true;
                //headerRangeDateTimeVal.Font.Size = 10;
                //headerRangeDateTimeVal.Merge(Type.Missing);
                //headerRangeDateTimeVal.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

                #endregion

                int excelSheetRow = this.WriteDataToTheSpecifiedRange(ds.Tables[0], range, rowcout);

                if (istotal)
                {

                    var colCount = ds.Tables[0].Columns.Count;
                    var dataRowCount = ds.Tables[0].Rows.Count;
                    var headerRangeTotal = XLsheet.Range[XLsheet.Cells[rowcout + dataRowCount + 1, 1], XLsheet.Cells[rowcout + dataRowCount + 1, columnScape]];
                    headerRangeTotal[1, 1] = "Total";
                    headerRangeTotal.Font.Bold = true;
                    headerRangeTotal.Font.Size = 12;
                    headerRangeTotal.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.ColorTranslator.FromHtml("#CC99FF"));
                    headerRangeTotal.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
//.........这里部分代码省略.........
开发者ID:mehedicse,项目名称:formiginationNET,代码行数:101,代码来源:AzExportToExcel.cs

示例6: ExcelHandler

 public ExcelHandler(string filename, int tabcount, string formula)
 {
     xlApp = new Microsoft.Office.Interop.Excel.Application();
     if (xlApp == null)
     {
         isOK = false;
         MessageBox.Show("Microsoft Excel не установлен или установлен некорректно");
         //  System.Windows.Forms.Application.Exit()
     }
     else
     {
         isOK = true;
         xlApp.SheetsInNewWorkbook = tabcount;
         xlWorkBook = xlApp.Workbooks.Add(Type.Missing);
         xlWorkBook.SaveAs(filename);
         string[] temp = formula.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
         advisabilityFormula = formula;
     }
 }
开发者ID:Witmaster,项目名称:SEMRushAPI,代码行数:19,代码来源:ExcelHandler.cs

示例7: Open

        public void Open(string filePath)
        {
            excel = new Application {DisplayAlerts = false};

            workbooks = excel.Workbooks;

            if (File.Exists(filePath))
            {
                workbook = workbooks.Open(filePath);
            }
            else
            {
                workbook = workbooks.Add();

                workbook.SaveAs(filePath);
            }

            worksheet = workbook.Worksheets[1] as Worksheet;

            if (worksheet == null) throw new NullReferenceException("worksheet");
        }
开发者ID:AndreyNesterkin,项目名称:GolfTestingProject,代码行数:21,代码来源:ExcelWriter.cs

示例8: SaveAs

 public bool SaveAs(string fileName, System.Data.DataTable dataTable)
 {
     if (dataTable == null || dataTable.Rows.Count == 0) return false;
     if (xlApp == null) return false;
     _workbook = xlApp.Workbooks.Add(Type.Missing);
     _worksheet = (Worksheet)_workbook.Worksheets[1];
     for (var i = 0; i < dataTable.Columns.Count; i++)
     {
         _worksheet.Cells[1, i + 1] = dataTable.Columns[i].ColumnName;
         //range = (Range)worksheet.Cells[1, i + 1];
         //range.Interior.ColorIndex = 15;
         //range.Font.Bold = true;
     }
     _workbook.SaveAs(fileName,XlFileFormat.xlWorkbookNormal, "", "", false, false, XlSaveAsAccessMode.xlExclusive,XlPlatform.xlWindows, false, false, false, false);
     _workbook.Close(true, fileName, false);
     xlApp.Quit();
     _connectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + fileName + "';Extended Properties=Excel 8.0;"; // строка подключения
     using (var excelConn = new System.Data.OleDb.OleDbConnection(_connectionString)) // используем OleDb
     {
         var queryValues = String.Empty;
         excelConn.Open();
         for (var i = 0; i < dataTable.Rows.Count; i++)
         {
             for (var c = 0; c < dataTable.Columns.Count; c++)
             {
                 queryValues += dataTable.Rows[i][c] + "','";
             }
             queryValues = queryValues.Substring(0, queryValues.Length - 3);
             var writeCmd = new System.Data.OleDb.OleDbCommand("INSERT INTO [Лист1$] VALUES ('" + queryValues + "')", excelConn);
             writeCmd.ExecuteNonQuery(); // вставляем данные в лист1 файла - filename
             writeCmd.Dispose();
             queryValues = String.Empty;
         }
         excelConn.Close();
     }
     return System.IO.File.Exists(fileName);
 }
开发者ID:pulse-computer-consulting,项目名称:NucleusPub,代码行数:37,代码来源:Excel.cs

示例9: saveReport

        private static void saveReport(IBackgroundContext context, ReestrDdParams args, string insurerName, Account smpBill,
            Workbook newDoc)
        {
            if (!string.IsNullOrEmpty(args.DirName) && Directory.Exists(args.DirName))
            {
                if (!string.IsNullOrEmpty(insurerName))
                {
                    var dirName = Path.Combine(args.DirName, insurerName);
                    if (!Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    var fileName = Path.Combine(dirName,
                        "Реестр " + Enum.GetName(typeof (AccountType), smpBill.AccountType) +
                        " к счету №" + smpBill.Number + " от " +
                        smpBill.SettleDate.ToString("ddMMyy") +
                        " " + insurerName);
                    try
                    {
                        if (File.Exists(fileName))
                            File.Delete(fileName);
                        newDoc.SaveAs(fileName);
                    }
                    catch (Exception e)
                    {
                        context.ReportError("Ошибка сохранения файла {0}: {1}", fileName, e.Message);
                    }
                }
            }
        }
开发者ID:vvboborykin,项目名称:VistaMedTools,代码行数:31,代码来源:ReestrDd.cs

示例10: WorkBook

        /// <summary>
        /// Creates a new Workbook with filepath as input
        /// </summary>
        internal WorkBook(string filePath)
        {
            wb = ExcelInterop.App.Workbooks.Add();
            Name = filePath;

            if (!String.IsNullOrEmpty(filePath))
            {
                wb.SaveAs(filePath);
            }
        }
开发者ID:TheChosen0ne,项目名称:Dynamo,代码行数:13,代码来源:Excel.cs

示例11: WorkBook

        /// <summary>
        /// Creates a new Workbook with filepath and sheet name as input
        /// </summary>
        internal WorkBook(string filePath)
        {            
            Name = filePath;

            if (!String.IsNullOrEmpty(filePath))
            {
                try
                {
                    Workbook workbook = ExcelInterop.App.Workbooks.Open(filePath);
                    wb = workbook;
                    wb.Save();
                    
                }
                catch (Exception)
                {
                    // Exception is thrown when there is no existing workbook with the given filepath
                    wb = ExcelInterop.App.Workbooks.Add();
                    wb.SaveAs(filePath);
                }
            }
            else
                wb = ExcelInterop.App.Workbooks.Add();
        }
开发者ID:heegwon,项目名称:Dynamo,代码行数:26,代码来源:Excel.cs

示例12: SaveXLS

        private void SaveXLS(Patient patient)
        {
            if (patient.results.Count > 0)
            {
                try
                {
                    // Открываем приложение
                    application = new Microsoft.Office.Interop.Excel.Application
                    {
                        DisplayAlerts = false
                    };

                    // Файл шаблона
                    const string template = "resources/template.xlt";

                    // Открываем книгу
                    workBook = application.Workbooks.Open(Path.Combine(Environment.CurrentDirectory, template));

                    // Получаем активную таблицу
                    worksheet = workBook.ActiveSheet as Worksheet;

                    // Записываем данные
                    //worksheet.Range["A2"].Value = DateTime.Now;
                    worksheet.Range["A1"].Value = "Название сеанса";
                    worksheet.Range["B1"].Value = "Дата";
                    worksheet.Range["C1"].Value = "Продолжительность";
                    worksheet.Range["D1"].Value = "Горизонтальное отклонение";
                    worksheet.Range["E1"].Value = "Горизонтальное отклонение (динамика)";
                    worksheet.Range["F1"].Value = "Вертикальное отклонение";
                    worksheet.Range["G1"].Value = "Вертикальное отклонение (динамика)";
                    worksheet.Range["H1"].Value = "Попадания";
                    worksheet.Range["I1"].Value = "Промахи";
                    worksheet.Range["J1"].Value = "Баллы";
                    worksheet.Range["K1"].Value = "Комментарий";
                    for (int i = 0; i < patient.results.Count; i++)
                    {
                        worksheet.Range["A" + (i + 2).ToString()].Value = patient.results[i].Name;
                        worksheet.Range["B" + (i + 2).ToString()].Value = patient.results[i].Date.ToShortDateString() + " " + patient.results[i].Date.ToShortTimeString();
                        worksheet.Range["C" + (i + 2).ToString()].Value = patient.results[i].Length.ToString();
                        worksheet.Range["D" + (i + 2).ToString()].Value = patient.results[i].HorDev.ToString();
                        worksheet.Range["E" + (i + 2).ToString()].Value = patient.results[i].HorDevDin.ToString();
                        worksheet.Range["F" + (i + 2).ToString()].Value = patient.results[i].VerDev.ToString();
                        worksheet.Range["G" + (i + 2).ToString()].Value = patient.results[i].VerDevDin.ToString();
                        worksheet.Range["H" + (i + 2).ToString()].Value = patient.results[i].Hit.ToString();
                        worksheet.Range["I" + (i + 2).ToString()].Value = patient.results[i].Miss.ToString();
                        worksheet.Range["J" + (i + 2).ToString()].Value = patient.results[i].Balls.ToString();
                        worksheet.Range["K" + (i + 2).ToString()].Value = patient.results[i].Comment;
                    }
                    bufar = patient.AverageResult();
                    worksheet.Range["A" + (patient.results.Count + 4).ToString()].Value = "Средний результат";
                    worksheet.Range["C" + (patient.results.Count + 4).ToString()].Value = bufar.Length.ToString();
                    worksheet.Range["D" + (patient.results.Count + 4).ToString()].Value = bufar.HorDev.ToString();
                    worksheet.Range["E" + (patient.results.Count + 4).ToString()].Value = bufar.HorDevDin.ToString();
                    worksheet.Range["F" + (patient.results.Count + 4).ToString()].Value = bufar.VerDev.ToString();
                    worksheet.Range["G" + (patient.results.Count + 4).ToString()].Value = bufar.VerDevDin.ToString();
                    worksheet.Range["H" + (patient.results.Count + 4).ToString()].Value = bufar.Hit.ToString();
                    worksheet.Range["I" + (patient.results.Count + 4).ToString()].Value = bufar.Miss.ToString();
                    worksheet.Range["J" + (patient.results.Count + 4).ToString()].Value = bufar.Balls.ToString();
                    worksheet.Range["K" + (patient.results.Count + 4).ToString()].Value = bufar.Comment;
                    bufbr = patient.BestResults();
                    worksheet.Range["A" + (patient.results.Count + 5).ToString()].Value = "Лучший результат";
                    worksheet.Range["C" + (patient.results.Count + 5).ToString()].Value = bufbr.Length.ToString();
                    worksheet.Range["D" + (patient.results.Count + 5).ToString()].Value = bufbr.HorDev.ToString();
                    worksheet.Range["E" + (patient.results.Count + 5).ToString()].Value = bufbr.HorDevDin.ToString();
                    worksheet.Range["F" + (patient.results.Count + 5).ToString()].Value = bufbr.VerDev.ToString();
                    worksheet.Range["G" + (patient.results.Count + 5).ToString()].Value = bufbr.VerDevDin.ToString();
                    worksheet.Range["H" + (patient.results.Count + 5).ToString()].Value = bufbr.Hit.ToString();
                    worksheet.Range["I" + (patient.results.Count + 5).ToString()].Value = bufbr.Miss.ToString();
                    worksheet.Range["J" + (patient.results.Count + 5).ToString()].Value = bufbr.Balls.ToString();
                    worksheet.Range["K" + (patient.results.Count + 5).ToString()].Value = bufbr.Comment;
                    //сохранение
                     SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Таблица результатов пациентов (*.xls)|*.xls";
                    sfd.FileName = patient.Name + "_результаты" + ".xls";
                    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        workBook.SaveAs(sfd.FileName);

                    //закрытие процесса
                    if (application != null)
                    {
                        int excelProcessId = -1;
                        GetWindowThreadProcessId(application.Hwnd, ref excelProcessId);

                        Marshal.ReleaseComObject(worksheet);
                        workBook.Close();
                        Marshal.ReleaseComObject(workBook);
                        application.Quit();
                        Marshal.ReleaseComObject(application);

                        application = null;
                        // Прибиваем висящий процесс
                        try
                        {
                            Process process = Process.GetProcessById(excelProcessId);
                            process.Kill();
                        }
                        finally { }
                    }
                }
                catch (Exception)
//.........这里部分代码省略.........
开发者ID:naithar,项目名称:Gamma,代码行数:101,代码来源:Form1.cs

示例13: generateReport

        public void generateReport(string fileName)
        {
            try
            {
                if (Owner != null)
                {
                    if (Owner.TestRunner != null)
                    {
                        m_xlApp = new Microsoft.Office.Interop.Excel.Application();
                        m_xlWorkBook = m_xlApp.Workbooks.Add(misValue);
                        m_xlWorkSheet = (Worksheet)m_xlWorkBook.Worksheets.get_Item(1);
                        m_xlWorkSheet.Cells[1, 1] = "_Test_Phase_Number";
                        m_xlWorkSheet.Cells[1, 2] = "_Type";
                        m_xlWorkSheet.Cells[1, 3] = "Object Text";
                        m_xlWorkSheet.Cells[1, 4] = "_Expected_Result";
                        m_xlWorkSheet.Cells[1, 5] = "TestCaseName";
                        (m_xlWorkSheet.Range[m_xlWorkSheet.Cells[1, 1], m_xlWorkSheet.Cells[1, 5]]).Interior.Color = XlRgbColor.rgbLightCyan;
                        int j = 2;

                        foreach (ITestSuit suit in Owner.TestRunner.TestSuits)
                        {
                            foreach (ItestCase test in suit.TestCases)
                            {

                                m_xlWorkSheet.Cells[j, 1] = test.TestPhaseNumber;
                                m_xlWorkSheet.Cells[j, 2] = "Test Phase Number";
                                m_xlWorkSheet.Cells[j, 3] = test.TestPhaseNumber;
                                j++;
                                m_xlWorkSheet.Cells[j, 2] = "Test Description";
                                m_xlWorkSheet.Cells[j, 3] = test.TestDescription;

                                foreach (string precondition in test.TestPrecondition)
                                {
                                    j++;
                                    m_xlWorkSheet.Cells[j, 2] = "Test Pre-Condition";
                                    m_xlWorkSheet.Cells[j, 3] = precondition + "\n";

                                }

                                foreach (string TestSteps in test.TestSteps)
                                {
                                    j++;
                                    m_xlWorkSheet.Cells[j, 2] = "Test Step";
                                    m_xlWorkSheet.Cells[j, 3] = TestSteps + "\n";

                                }
                                string ExpectedResultString = "";
                                foreach (string ExpectedResult in test.ExpectedResult)
                                {
                                    ExpectedResultString += ExpectedResult + "\n";

                                }
                                m_xlWorkSheet.Cells[j, 4] = ExpectedResultString;
                                m_xlWorkSheet.Cells[j, 5] = test.Name;
                                j++;

                            }

                        }
                        oRange = m_xlWorkSheet.Range[m_xlWorkSheet.Cells[1, 1], m_xlWorkSheet.Cells[j, 5]];
                        oRange.Borders.get_Item(XlBordersIndex.xlEdgeLeft).LineStyle = XlLineStyle.xlContinuous;
                        oRange.Borders.get_Item(XlBordersIndex.xlEdgeRight).LineStyle = XlLineStyle.xlContinuous;
                        oRange.Borders.get_Item(XlBordersIndex.xlInsideHorizontal).LineStyle = XlLineStyle.xlContinuous;
                        oRange.Borders.get_Item(XlBordersIndex.xlInsideVertical).LineStyle = XlLineStyle.xlContinuous;

                        m_xlWorkBook.SaveAs(fileName, XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                        m_xlWorkBook.Close(true, misValue, misValue);
                        m_xlApp.Quit();

                        releaseObject(m_xlWorkSheet);
                        releaseObject(m_xlWorkBook);
                        releaseObject(m_xlApp);
                        MessageBox.Show("Excel report Generated");

                    }
                }
            }
            catch
            {

            }
        }
开发者ID:ajithpadman,项目名称:GoogleUnitTestIDE,代码行数:82,代码来源:ExcelReportGenerator.cs

示例14: GenerateExcel

        public void GenerateExcel(DataSet receiveDS, string filePath, int rowcout)
        {
            ds = receiveDS;
            strFileName = filePath;
            try
            {
                application = new Application();
                application.Visible = false;//true;
                application.DisplayAlerts = false;

                workbooks = application.Workbooks;
                workbook = (Workbook)application.Workbooks.Add(1);
                workbook.SaveAs(strFileName, XlFileFormat.xlWorkbookNormal, null, null, false, false,
                                XlSaveAsAccessMode.xlExclusive, false, false, null, null, false);

                range = ((Worksheet)workbook.ActiveSheet).get_Range("A1", "AZ1");
                range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                //range = worksheet.Cells;
                int excelSheetRow = this.WriteDataToTheSpecifiedRange(ds.Tables[0], range, rowcout);

                range = ((Worksheet)workbook.ActiveSheet).get_Range("A1", "AZ1");
                range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

                //range = worksheet.Cells;
                //this.OverWriteDataToTheSpecifiedRange(ds.Tables[skuDataTableIndex], range);

                //worksheet.get_Range("A1", "AZ1").EntireColumn.AutoFit();
                //worksheet.SaveAs(strFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                //                 Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                Worksheet XLsheet = ((Worksheet)workbook.ActiveSheet);

                XLsheet.Columns.AutoFit();

                XLsheet.Name = ds.Tables[0].TableName;
                workbook.Save();

            }
            catch (Exception exp)
            {
                //string path = System.Web.HttpContext.Current.Server.MapPath(@"");
                //path = path.Substring(0, path.Length - 3);
                //System.IO.File.AppendAllText("LeaveYearTemp" + "/errorLog.txt", exp.Message);
                throw exp;
            }
            finally
            {
                DisposeExcelObject();
            }
        }
开发者ID:mehedicse,项目名称:formiginationNET,代码行数:49,代码来源:AzExportToExcel.cs

示例15: WorkBook

        /// <summary>
        /// (SaveAsExcelWorkbook node)
        /// </summary>
        /// <param name="wbook"></param>
        /// <param name="filename"></param>
        internal WorkBook(WorkBook wbook, string filename)
        {
            Name = filename;
            wb = wbook.wb;

            if (wb.FullName == filename)
                wb.Save();
            else
            {
                try
                {
                    Workbook workbook = ExcelInterop.App.Workbooks.Open(filename);
                    workbook.Close(false);
                }
                catch (Exception)
                {
                }

                wb.SaveAs(filename);
            }

        }
开发者ID:ankushraizada,项目名称:Dynamo,代码行数:27,代码来源:Excel.cs


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