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


C# Workbook.ExportAsFixedFormat方法代码示例

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


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

示例1: MakeExcelFile

        /// <summary>
        /// Сохраняем файлы в формате пдф и ексель в папки
        /// </summary>
        public void MakeExcelFile(decimal moneyAtStart, decimal moneyBalance)
        {
            string dateFile;    //Повна назва файлу для зберігання
            try
            {
                CreateFolderForSavingFile(excelFilePath, out dateFile);

                oApp = new Excel.Application();
                oBook = oApp.Workbooks.Add();
                oSheet = (Excel.Worksheet)oBook.Worksheets.get_Item(1);

                // Заповнюємо excel файл данними
                CreateFullFile();
                InputInformationFields(moneyAtStart, moneyBalance);

                // Зберігаємо файл в форматі екселя
                oBook.SaveAs(dateFile + ".xlsx");

                CreateFolderForSavingFile(pdfFilePath, out dateFile);

                // Додаткова перевірка при зберіганні pdf файла на встановлене розширення в Office
                try
                {
                    oBook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, dateFile + ".pdf");
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Помилка при збереженні PDF файла. Перевірте чи у Вас встановлене розширення в "
                        + " Microsoft Office для збереження файлів в форматі PDF/XPS.", "Помилка при збереженні PDF",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }               
                catch (Exception)
                {
                    MessageBox.Show("Помилка при збереженні pdf файла.");
                }


                MessageBox.Show("Дані збережено!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
            finally
            {
                oBook.Close();
                oApp.Quit();
            }
        }
开发者ID:franko-vv,项目名称:Input-and-Outlay,代码行数:52,代码来源:CreateExcelFile.cs

示例2: Parse

        public void Parse(object src, object dest)
        {
            if (src == null || string.IsNullOrEmpty(src.ToString()))
            {
                throw new ArgumentNullException("源文件不能为空");
            }
            if (dest == null || string.IsNullOrEmpty(dest.ToString()))
            {
                throw new ArgumentNullException("目标路径不能为空");
            }

            try
            {
                xlsx = excelApp.Workbooks.Open(src.ToString(), missing, missing, missing, missing, missing
                    , missing, missing, missing, missing, missing, missing, missing, missing, missing);

                int startPage = 0;
                int endPage = 10;
                if (xlsx != null)
                {
                    xlsx.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, dest, missing, missing, missing, missing, missing, missing,
                        missing);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (xlsx != null)
                {
                    xlsx.Close(false, missing, missing);
                    xlsx = null;
                }

                if (excelApp!= null)
                {
                    excelApp.Quit();
                    excelApp = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
开发者ID:qiaowanghappy,项目名称:DocViewer,代码行数:47,代码来源:ExcelParser.cs

示例3: Convert

        // private Excel.Worksheet sheet;
        public override void Convert(String inputFile, String outputFile)
        {
            Object nothing = Type.Missing;
            try
            {
                if (!File.Exists(inputFile))
                {
                    throw new ConvertException("File not Exists");
                }

                if (IsPasswordProtected(inputFile))
                {
                    throw new ConvertException("Password Exist");
                }

                app = new Excel.Application();
                books = app.Workbooks;
                book = books.Open(inputFile, false, true, nothing, nothing, nothing, true, nothing, nothing, false, false, nothing, false, nothing, false);

                bool hasContent = false;
                foreach (Excel.Worksheet sheet in book.Worksheets)
                {
                    Excel.Range range = sheet.UsedRange;
                    if (range != null) {
                        Excel.Range found = range.Cells.Find("*", nothing, nothing, nothing, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, nothing, nothing, nothing);
                        if (found != null) hasContent = true;
                        releaseCOMObject(found);
                        releaseCOMObject(range);
                    }
                }

                if (!hasContent) throw new ConvertException("No Content");
                book.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, outputFile, Excel.XlFixedFormatQuality.xlQualityMinimum, false, false, nothing, nothing, false, nothing);
            }
            catch (Exception e)
            {
                release();
                throw new ConvertException(e.Message);
            }

            release();
        }
开发者ID:teambition,项目名称:OfficeConverter,代码行数:43,代码来源:ExcelConverter.cs

示例4: GetReport


//.........这里部分代码省略.........
                _excelApp.Columns[2].VerticalAlignment = Excel.Constants.xlCenter;

                //вывод времени

                var times = Lessons.Select(l => l.Lessons.Select(t => new
                {
                    StartTime = t.StartTime,
                    EndTime = t.EndTime,
                })).SelectMany(t => t.Select(d => d)).Distinct().OrderBy(d => d.StartTime);

                int col = 3;

                foreach (var t in times)
                {
                    _excelApp.Cells[14, col] = t.StartTime.ToString() + "-" + t.EndTime.ToString();
                    _excelApp.Columns[col].ColumnWidth = 19;
                    _excelApp.Columns[col].HorizontalAlignment = Excel.Constants.xlCenter;
                    _excelApp.Columns[col].VerticalAlignment = Excel.Constants.xlCenter;
                    col++;
                }

                int colCount = col - 1;

                var cellHeader1 = (Excel.Range)_excelApp.Cells[11, 1];
                var cellHeader2 = (Excel.Range)_excelApp.Cells[11, colCount];
                _excelApp.Cells.get_Range(cellHeader1, cellHeader2).Merge(Type.Missing);
                _excelApp.Cells.get_Range(cellHeader1, cellHeader2).HorizontalAlignment = Excel.Constants.xlCenter;
                cellHeader1 = (Excel.Range)_excelApp.Cells[12, 1];
                cellHeader2 = (Excel.Range)_excelApp.Cells[12, colCount];
                _excelApp.Cells.get_Range(cellHeader1, cellHeader2).Merge(Type.Missing);
                _excelApp.Cells.get_Range(cellHeader1, cellHeader2).HorizontalAlignment = Excel.Constants.xlCenter;

                //вывод дат

                int row = 15;
                foreach (var l in Lessons.OrderBy(l => l.Dates.OrderBy(d => d.Day).FirstOrDefault().DayOfWeek))
                {
                    _excelApp.Cells[row, 1] = l.DayOfWeek;
                    int rowStart = row;
                    foreach (var d in l.Dates.OrderBy(d => d.Date))
                    {
                        _excelApp.Cells[row, 2] = d.ToShortDateString();
                        row++;
                    }
                    int rowEnd = row - 1;
                    _excelApp.Cells.get_Range(string.Format("A{0}", rowStart), string.Format("A{0}", rowEnd)).Merge(Type.Missing);
                    for (int i = 3; i < col; i++)
                    {
                        Excel.Range cellStart = (Excel.Range)_excelApp.Cells[rowStart, i];
                        Excel.Range cellEnd = (Excel.Range)_excelApp.Cells[rowEnd, i];
                        _excelApp.Cells.get_Range(cellStart, cellEnd).Merge(Type.Missing);
                    }
                }

                //вывод занятий
                for (int i = 3; i < col; i++)
                {
                    for (int j = 15; j < row; j++)
                    {
                        string dayOfWeek = _excelApp.Cells[j, 1].Text;
                        string str1 = ((string)_excelApp.Cells[14, i].Text).Substring(0, 8);
                        TimeSpan startTime = TimeSpan.Parse(str1);
                        string str2 = ((string)_excelApp.Cells[14, i].Text).Substring(9, 8);
                        TimeSpan endTime = TimeSpan.Parse(str2);

                        var less = Lessons.Where(l => l.DayOfWeek == dayOfWeek).FirstOrDefault();
                        if (less != null)
                        {
                            var item = less.Lessons.Where(l => l.StartTime == startTime && l.EndTime == endTime).FirstOrDefault();
                            if (item != null)
                            {
                                _excelApp.Cells[j, i] = item.Group + "\n" + item.Instructor;
                            }
                        }
                    }
                }

                Excel.Range cell1 = (Excel.Range)_excelApp.Cells[14, 1];
                Excel.Range cell2 = (Excel.Range)_excelApp.Cells[row - 1, col - 1];
                var cells = _excelSheet.get_Range(cell1, cell2); // выделяем
                cells.Borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
                cells.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; // правая внешняя
                cells.Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; // левая внешняя
                cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; // нижняя внешняя
                cells.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous; // внутренние вертикальные
                cells.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.XlLineStyle.xlContinuous; // внутренние горизонтальные

                //_excelBook.SaveAs(_saveAsPath);
                _excelBook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, Filename: _saveAsPath);
            }
            catch (Exception)
            {
            }
            finally
            {
                _excelBook.Close(false);
                _excelApp.Quit();
            }
            return _saveAsPath;
        }
开发者ID:IvanNkl,项目名称:AutoSchool,代码行数:101,代码来源:ScheduleTheoryReport.cs

示例5: GetReport

        public string GetReport()
        {
            try
            {
                object misValue = System.Reflection.Missing.Value;
                _excelApp = new Excel.Application();
                _excelBook = _excelApp.Workbooks.Add(misValue);
                _excelSheet = (Excel.Worksheet)_excelBook.Worksheets.get_Item(1);

                _excelSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlPortrait;

                _excelApp.Cells[1, 1] = "ЗАО «Специализированная Автошкола»";
                _excelApp.Cells[2, 1] = "Юридический адрес:";
                _excelApp.Cells[3, 1] = "г. Могилев, ул. Школьная 16-405";
                _excelApp.Cells[4, 1] = "УНН: 600359652";
                _excelApp.Cells[5, 1] = "Р/с 3012205280013 в Ф-л ОАО Бел";
                _excelApp.Cells[6, 1] = "АПБ МОУ г. Могилев,";
                _excelApp.Cells[7, 1] = "пр-т Мира 91 код 942";
                _excelApp.Cells[8, 1] = "Телефон:(222) 290-45-65";
                _excelApp.Cells[9, 1] = "Директор: Хацкевич Андрей Евгеньевич";

                _excelApp.Cells[11, 1] = string.Format("График работы инструктора {0}", FIO);
                _excelApp.Cells[12, 1] = string.Format("с {0} по {1}", StartDate.ToShortDateString(), EndDate.ToShortDateString());

                var cellHeader1 = (Excel.Range)_excelApp.Cells[11, 1];
                var cellHeader2 = (Excel.Range)_excelApp.Cells[11, 4];
                _excelApp.Cells.get_Range(cellHeader1, cellHeader2).Merge(Type.Missing);
                _excelApp.Cells.get_Range(cellHeader1, cellHeader2).HorizontalAlignment = Excel.Constants.xlCenter;
                cellHeader1 = (Excel.Range)_excelApp.Cells[12, 1];
                cellHeader2 = (Excel.Range)_excelApp.Cells[12, 4];
                _excelApp.Cells.get_Range(cellHeader1, cellHeader2).Merge(Type.Missing);
                _excelApp.Cells.get_Range(cellHeader1, cellHeader2).HorizontalAlignment = Excel.Constants.xlCenter;

                _excelApp.Cells[14, 1] = "Дата";
                _excelApp.Columns[1].ColumnWidth = 15;
                _excelApp.Cells[14, 1].HorizontalAlignment = Excel.Constants.xlCenter;
                _excelApp.Columns[1].VerticalAlignment = Excel.Constants.xlCenter;

                _excelApp.Cells[14, 2] = "Время";
                _excelApp.Columns[2].ColumnWidth = 20;
                _excelApp.Columns[2].HorizontalAlignment = Excel.Constants.xlCenter;
                _excelApp.Columns[2].VerticalAlignment = Excel.Constants.xlCenter;

                _excelApp.Cells[14, 3] = "Тип занятия";
                _excelApp.Columns[3].ColumnWidth = 20;
                _excelApp.Columns[3].HorizontalAlignment = Excel.Constants.xlCenter;
                _excelApp.Columns[3].VerticalAlignment = Excel.Constants.xlCenter;

                _excelApp.Cells[14, 4] = "ФИО курсанта/Группа";
                _excelApp.Columns[4].ColumnWidth = 25;
                _excelApp.Columns[4].HorizontalAlignment = Excel.Constants.xlCenter;
                _excelApp.Columns[4].VerticalAlignment = Excel.Constants.xlCenter;

                int row = 15;

                foreach (var l in Lessons.OrderBy(l => (l.Date + l.StartTime)))
                {
                    _excelApp.Cells[row, 1] = l.Date.ToShortDateString();
                    _excelApp.Cells[row, 2] = l.StartTime.ToString() + "-" + l.EndTime.ToString();
                    _excelApp.Cells[row, 3] = l.Type;
                    _excelApp.Cells[row, 4] = l.Training;
                    row++;
                }

                Excel.Range cell1 = (Excel.Range)_excelApp.Cells[14, 1];
                Excel.Range cell2 = (Excel.Range)_excelApp.Cells[row - 1, 4];
                var cells = _excelSheet.get_Range(cell1, cell2); // выделяем
                cells.Borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
                cells.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; // правая внешняя
                cells.Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; // левая внешняя
                cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; // нижняя внешняя
                cells.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous; // внутренние вертикальные
                cells.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.XlLineStyle.xlContinuous; // внутренние горизонтальные

                row++;

                //_excelBook.SaveAs(_saveAsPath);
                _excelBook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, Filename: _saveAsPath);
            }
            catch (Exception)
            {
            }
            finally
            {
                _excelBook.Close(false);
                _excelApp.Quit();
            }
            return _saveAsPath;
        }
开发者ID:IvanNkl,项目名称:AutoSchool,代码行数:89,代码来源:ScheduleInstructorWorkReport.cs

示例6: GenerarReporte

 void GenerarReporte()
 {
     if (app == null)
         app = new E.Application();
     app.Visible = false;
     wb = app.Workbooks.Open(@rutas.RutaDeReportes + "\\facapt04.xlsx");
     E.Worksheet ws = wb.Worksheets[1];
     int index = 8;
     for (int i = dgvLista.SelectedRows.Count - 1; i >= 0 ; i--)
     {
         ws.Range["A" + index].Value2 = dgvLista.SelectedRows[i].Cells[1].Value.ToString();
         ws.Range["B" + index].Value2 = dgvLista.SelectedRows[i].Cells[2].Value.ToString();
         ws.Range["C" + index].Value2 = dgvLista.SelectedRows[i].Cells[3].Value.ToString();
         ws.Range["D" + index].Value2 = dgvLista.SelectedRows[i].Cells[4].Value.ToString();
         ws.Range["E" + index].Value2 = dgvLista.SelectedRows[i].Cells[5].Value.ToString();
         ws.Range["F" + index].Value2 = dgvLista.SelectedRows[i].Cells[6].Value.ToString();
         ws.Range["G" + index].Value2 = dgvLista.SelectedRows[i].Cells[7].Value.ToString();
         ws.Range["H" + index].Value2 = dgvLista.SelectedRows[i].Cells[8].Value.ToString();
         ws.Range["I" + index].Value2 = DateTime.Parse(dgvLista.SelectedRows[i].Cells[9].Value.ToString()).ToString("dd/MM/yyyy");
         if (string.IsNullOrEmpty(dgvLista.SelectedRows[i].Cells[10].Value.ToString() ) || string.IsNullOrWhiteSpace(dgvLista.SelectedRows[i].Cells[10].Value.ToString()))
             ws.Range["J" + index].Value2 = string.Empty;
         else
             ws.Range["J" + index].Value2 = DateTime.Parse(dgvLista.SelectedRows[i].Cells[10].Value.ToString()).ToString("dd/MM/yyyy");
         index++;
     }
     if (System.IO.File.Exists(System.IO.Path.GetTempPath() + "reporte.xlsx"))
         System.IO.File.Delete(System.IO.Path.GetTempPath() + "reporte.xlsx");
     if (System.IO.File.Exists(@rutas.RutaDeTemp + "/rpt_ProdEmpacado.pdf"))
         System.IO.File.Delete(@rutas.RutaDeTemp + "/rpt_ProdEmpacado.pdf");
     wb.SaveAs(System.IO.Path.GetTempPath() + "reporte.xlsx");
     wb.ExportAsFixedFormat(E.XlFixedFormatType.xlTypePDF, @rutas.RutaDeTemp + "/rpt_ProdEmpacado.pdf");
     VistasPrevias vp = new VistasPrevias();
     vp.Navegar(@rutas.RutaDeTemp + "/rpt_ProdEmpacado.pdf");
     vp.ShowDialog();
     vp.Dispose();
     wb.Close(false);
     app.Quit();
 }
开发者ID:GeMaths,项目名称:etiquetasPMM,代码行数:38,代码来源:Frm_ControlProductoEmpacado.cs


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