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


C# Application.CentimetersToPoints方法代码示例

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


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

示例1: Export

        private void Export()
        {
            string fileName = "Excel.xls";
            var rep = (ReportPreviewModel.Report as OrderFormReport);
            rep.ExportToXls(fileName, new XlsExportOptions());

            Microsoft.Office.Interop.Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application();
            Workbook ObjWorkBookGeneral;
            ObjWorkBookGeneral = ObjExcel.Workbooks.Open(Environment.CurrentDirectory + "\\" + fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


            if (File.Exists(Environment.CurrentDirectory + "\\" + fileName))
                File.Copy(Environment.CurrentDirectory + "\\" + fileName, Environment.CurrentDirectory + "\\Result_" + fileName, true);

            Workbook ObjWorkBookResult = ObjExcel.Workbooks.Open(Environment.CurrentDirectory + "\\Result_" + fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            (ObjWorkBookResult.ActiveSheet as Worksheet).UsedRange.Clear();

            try
            {
                Worksheet sheet = ObjWorkBookGeneral.ActiveSheet;

                if (sheet != null)
                {
                    Range range = sheet.UsedRange;
                    if (range != null)
                    {
                        int nRows = range.Rows.Count;
                        int nCols = range.Columns.Count;

                        Range tempRange;

                        Range startCell = null;
                        Range endCell = null;
                        string animationName = string.Empty;

                        int currentSheetIndex = 0;
                        int k = 0;
                        for (int i = 1; i <= nRows + 1; i++)
                        {
                            string d = range[i, 1].value;
                            if (d == "xrStart" || i == nRows + 1)
                            {
                                k = 1;
                                if (startCell != null || i == nRows + 1)
                                {
                                    endCell = range.Cells[i - 1, nCols];
                                    tempRange = range.Range[startCell, endCell];


                                    currentSheetIndex = currentSheetIndex + 1;

                                    ((Worksheet)ObjWorkBookResult.Sheets[currentSheetIndex]).Select(Type.Missing);


                                    ObjWorkBookResult.ActiveSheet.Name = animationName;
                                    tempRange.Copy(Type.Missing);
                                    ObjWorkBookResult.ActiveSheet.PasteSpecial(XlPasteType.xlPasteColumnWidths);
                                    ObjWorkBookResult.ActiveSheet.PasteSpecial(XlPasteType.xlPasteAllUsingSourceTheme);

                                    (ObjWorkBookResult.ActiveSheet as Worksheet).PageSetup.Orientation = XlPageOrientation.xlLandscape;
                                    (ObjWorkBookResult.ActiveSheet as Worksheet).PageSetup.TopMargin = ObjExcel.CentimetersToPoints(1);
                                    (ObjWorkBookResult.ActiveSheet as Worksheet).PageSetup.BottomMargin = ObjExcel.CentimetersToPoints(1);
                                    (ObjWorkBookResult.ActiveSheet as Worksheet).PageSetup.HeaderMargin = 0;
                                    (ObjWorkBookResult.ActiveSheet as Worksheet).PageSetup.FooterMargin = 0;
                                    (ObjWorkBookResult.ActiveSheet as Worksheet).PageSetup.LeftMargin = ObjExcel.CentimetersToPoints(1);
                                    (ObjWorkBookResult.ActiveSheet as Worksheet).PageSetup.RightMargin = ObjExcel.CentimetersToPoints(1);


                                    startCell = range.Cells[i, 1];
                                    if (range.Cells[i + 1, 1].value != null)
                                    {
                                        animationName = range.Cells[i + 1, 1].value;
                                        animationName = RemoveSpecialCharacters(animationName);
                                        if (animationName.Length > 30)
                                            animationName = animationName.Substring(0, 30);

                                        ObjWorkBookResult.Sheets.Add(Type.Missing, ObjWorkBookResult.ActiveSheet,
                                                                     Type.Missing, Type.Missing);
                                    }
                                }
                                else
                                {
                                    startCell = range.Cells[i, 1];
                                    animationName = range.Cells[i + 1, 1].value;
                                    animationName = RemoveSpecialCharacters(animationName);
                                    if (animationName.Length > 30)
                                        animationName = animationName.Substring(0, 30);
                                }
                            }

                            Worksheet sh = (ObjWorkBookResult.ActiveSheet as Worksheet);
                            (sh.Rows[k] as Range).RowHeight = (range.Rows[i] as Range).RowHeight;
                            k++;

                        }
                    }
                }
            }
            finally
            {
//.........这里部分代码省略.........
开发者ID:ddksaku,项目名称:loreal,代码行数:101,代码来源:OrderFormReportViewModel.cs


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