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


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

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


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

示例1: PrintFpcLotCard


//.........这里部分代码省略.........
                        dgvRow.Cells["print_msg"].Value = "正在插入单体图图片到批量卡...";
                        //各列列宽
                        dgvList.AutoResizeColumns();
                        //显示
                        Application.DoEvents();
                        //设置为活动
                        ((Excel._Workbook)xlBook).Activate();
                        ((Excel._Worksheet)xlSheet).Select();
                        //在excel中插入该图片并设置分页
                        string strError = string.Empty;
                        if (!InsertDanTiTuImageToExcelSheet(xlSheet, imgName, out strError))
                        {
                            //返回错误
                            dgvRow.Cells["print_msg"].Value = "插入单体图图片到批量卡失败!";
                            return;
                        }
                    }
                    //退出
                    break;
            }

            //待打印成的文件名称
            string tmpFileName = string.Format("{0}lotcard.xls", strPath);
            //删除之前的文件
            if (File.Exists(tmpFileName))
            {
                File.Delete(tmpFileName);
            }
            //打印设置
            var xlPageSetup = xlSheet.PageSetup;
            xlPageSetup.FitToPagesWide = 1;
            xlPageSetup.FitToPagesTall = 1;
            xlPageSetup.RightFooter = @"&""宋体,倾斜""&10打印时间:&D &T";
            xlPageSetup.FooterMargin = xlApp.InchesToPoints(0.18d);
            //保存该批量卡
            xlBook.SaveAs(tmpFileName);

            //不打印只保存批量卡和cov卡
            //不打印只保存单元图
            //不打印保存批量卡和cov卡以及单元图
            //只打印批量卡和cov卡
            //只打印单元图
            //打印批量卡和cov卡以及单元图
            //打印
            switch (cboPrintSettings.Text.Trim())
            {
                case "打印批量卡和cov卡以及单元图":
                    //显示状态
                    dgvRow.Cells["print_msg"].Value = "正在打印批量卡和cov卡以及单元图...";
                    //各列列宽
                    dgvList.AutoResizeColumns();
                    //显示
                    Application.DoEvents();
                    //打印LOT卡和单体图
                    xlSheet.PrintOut(From: 1, To: 2, Copies: 1, Collate: true);
                    break;
                case "只打印批量卡":
                    //显示状态
                    dgvRow.Cells["print_msg"].Value = "正在打印批量卡...";
                    //各列列宽
                    dgvList.AutoResizeColumns();
                    //显示
                    Application.DoEvents();
                    //打印LOT卡
                    xlSheet.PrintOut(From: 1, To: 1, Copies: 1, Collate: true);
                    break;
开发者ID:yangdan8,项目名称:ydERPGJ,代码行数:67,代码来源:frmMain.cs

示例2: FormatExcel


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

            #region 调整列宽
            excelSheet.get_Range("A1", "A1").ColumnWidth = 18;
            excelSheet.get_Range("B1", "B1").ColumnWidth = 18;
            excelSheet.get_Range("C1", "C1").ColumnWidth = 0.3;
            excelSheet.get_Range("D1", "D1").ColumnWidth = 18;
            excelSheet.get_Range("E1", "E1").ColumnWidth = 18;
            #endregion

            #region 调整行高
            excelSheet.get_Range("A1", "A1").RowHeight = 22.5;
            excelSheet.get_Range("A2", "A2").RowHeight = 22.5;
            excelSheet.get_Range("A3", "A3").RowHeight = 23.25;
            excelSheet.get_Range("A4", "A4").RowHeight = 21;

            excelSheet.get_Range("A" + Convert.ToString(5), "A" + Convert.ToString(intDtEnd + 2)).RowHeight = 14.25;

            #endregion

            #region 设置线条
            rng = excelSheet.get_Range("A4", "E" + Convert.ToString(intDtEnd));
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeTop].LineStyle = MSOffice.XlLineStyle.xlContinuous;
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeTop].Weight = MSOffice.XlBorderWeight.xlMedium;
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeBottom].LineStyle = MSOffice.XlLineStyle.xlContinuous;
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeBottom].Weight = MSOffice.XlBorderWeight.xlMedium;
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeLeft].LineStyle = MSOffice.XlLineStyle.xlContinuous;
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeLeft].Weight = MSOffice.XlBorderWeight.xlMedium;
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeRight].LineStyle = MSOffice.XlLineStyle.xlContinuous;
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeRight].Weight = MSOffice.XlBorderWeight.xlMedium;
            rng.Borders[MSOffice.XlBordersIndex.xlInsideHorizontal].LineStyle = MSOffice.XlLineStyle.xlContinuous;
            rng.Borders[MSOffice.XlBordersIndex.xlInsideVertical].LineStyle = MSOffice.XlLineStyle.xlContinuous;

            rng = excelSheet.get_Range("C4", "C" + Convert.ToString(intDtEnd));
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeLeft].Weight = MSOffice.XlBorderWeight.xlMedium;
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeRight].Weight = MSOffice.XlBorderWeight.xlMedium;
            rng.Borders[MSOffice.XlBordersIndex.xlInsideHorizontal].LineStyle = MSOffice.XlLineStyle.xlLineStyleNone;

            rng = excelSheet.get_Range("A4", "E4");
            rng.Borders[MSOffice.XlBordersIndex.xlEdgeBottom].Weight = MSOffice.XlBorderWeight.xlMedium;
            #endregion

            #region 设置字体格式与排列
            //名称居左,金额居右
            excelSheet.get_Range("A5", "A" + Convert.ToString(intDtEnd)).HorizontalAlignment = MSOffice.XlHAlign.xlHAlignLeft;
            excelSheet.get_Range("B5", "B" + Convert.ToString(intDtEnd)).HorizontalAlignment = MSOffice.XlHAlign.xlHAlignRight;
            excelSheet.get_Range("D5", "D" + Convert.ToString(intDtEnd)).HorizontalAlignment = MSOffice.XlHAlign.xlHAlignLeft;
            excelSheet.get_Range("E5", "E" + Convert.ToString(intDtEnd)).HorizontalAlignment = MSOffice.XlHAlign.xlHAlignRight;
            #endregion

            //几个特殊单元格
            excelSheet.get_Range("A1", "E1").Merge(true);
            excelSheet.get_Range("A2", "E2").Merge(true);

            rng = excelSheet.get_Range("A1", "E2");
            rng.Font.Bold = true;
            rng.Font.Size = 18;
            rng.Font.Name = "楷体_GB2312";
            rng.HorizontalAlignment = MSOffice.XlHAlign.xlHAlignCenter;
            rng.VerticalAlignment = MSOffice.XlVAlign.xlVAlignBottom;

            ////////////////////测试/////////////////////////////
            rng.Font.Background = 1;
            rng.Font.Bold = true;
            rng.Font.Size = 18;
            rng.Font.Name = "";
            rng.Font.Underline = true;
            rng.Font.Underline = MSOffice.XlUnderlineStyle.xlUnderlineStyleSingle;
            rng.Font.ThemeFont = MSOffice.XlThemeFont.xlThemeFontNone;
            excelApp.ActiveCell.FormulaR1C1 = "";
            rng.Borders[MSOffice.XlBordersIndex.xlInsideVertical].LineStyle = MSOffice.XlLineStyle.xlContinuous;
            rng.Borders[MSOffice.XlBordersIndex.xlInsideVertical].Weight = MSOffice.XlBorderWeight.xlMedium;
            rng.AutoFit();
            rng.Rows.AutoFit();
            rng.Columns.AutoFit();

            rng = excelSheet.get_Range("A3", "A3");
            rng.Font.Bold = false;
            rng.Font.Size = 11;
            rng.Font.Name = "楷体_GB2312";
            rng.HorizontalAlignment = MSOffice.XlHAlign.xlHAlignLeft;

            rng = excelSheet.get_Range("A4", "E4");
            rng.Font.Bold = true;
            rng.Font.Size = 12;
            rng.HorizontalAlignment = MSOffice.XlHAlign.xlHAlignCenter;

            #region 设置打印格式
            excelSheet.PageSetup.PaperSize = MSOffice.XlPaperSize.xlPaperA4;
            //excelSheet.PageSetup.FitToPagesWide = 1;
            //excelSheet.PageSetup.FitToPagesTall = 100;
            //excelSheet.PageSetup.Zoom = false;
            excelSheet.PageSetup.LeftMargin = excelApp.InchesToPoints(1 / 2.54 * 1.3);
            excelSheet.PageSetup.RightMargin = excelApp.InchesToPoints(1 / 2.54 * 1.3);
            excelSheet.PageSetup.TopMargin = excelApp.InchesToPoints(1 / 2.54 * 1.9);
            excelSheet.PageSetup.BottomMargin = excelApp.InchesToPoints(1 / 2.54 * 1.9);
            excelSheet.PageSetup.FooterMargin = excelApp.InchesToPoints(1 / 2.54 * 0.5);
            excelSheet.PageSetup.Orientation = MSOffice.XlPageOrientation.xlLandscape;
            #endregion
        }
开发者ID:chanfengsr,项目名称:AllPrivateProject,代码行数:101,代码来源:OfficeInfo.cs


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