c#的excel边距设置2007-08-17 16:07
exce.Application.Workbooks.Add(true);
Workbook books=(Excel.Workbook)exce.Workbooks[1];
Excel.Worksheet sheets=(Excel.Worksheet)books.Worksheets[1];
exce.Cells.VerticalAlignment=2;//单元格文字垂直居中
sheets.Cells.Font.Name="宋体";
sheets.Cells.Font.Size=11;
//设置表格标题
sheets.Cells[1,1]="正在生成表格,请稍候..... 警告:在生成期间,请不要编辑单元格";
exce.get_Range("A1","P1").MergeCells=true;//合并单元格
exce.get_Range("a1","a1").HorizontalAlignment=3;//水平居中
exce.get_Range("a1","a1").Font.Name="黑体";
exce.get_Range("a1","a1").Font.Size=20;
exce.get_Range("a1","a1").Font.Bold=true;
exce.get_Range("A2","P2").MergeCells=true;
sheets.Cells[2,1]="部门:"+treeView1.SelectedNode.FullPath+
" (共计:"+RowCount.ToString()+"项)";
//设置表格值
.......
exce.get_Range("a3","p3").HorizontalAlignment=3;//列名称居中
sheets.Columns.AutoFit();//设置最合适列宽
......
exce.get_Range("A3", ENDSELECT).Borders.LineStyle = 1;//设置选中单元格的网格线
sheets.Cells.Select();
sheets.Columns.AutoFit();//再次设置最合适列宽
sheets.Cells[1,1]=" 总帐";
sheets.Cells[2,1]="部门:"+treeView1.SelectedNode.FullPath+
" (共计:"+RowCount.ToString()+"项,合计数量:"+
Numer.ToString()+" 合计金额:"+jine.ToString("C2")+"元)";
ENDSELECT="A"+(RowCount+3);
exce.get_Range("A3",ENDSELECT).HorizontalAlignment=3;//设置序号列居中
ENDSELECT="G"+(RowCount+3);
exce.get_Range("G4", ENDSELECT).NumberFormatLocal="#,##0.00_ ";//设置金额列为货币式
exce.get_Range("B4","B4").Select();
exce.ActiveWindow.FreezePanes=true;//冻结窗口
//页面设置
exce.ActiveWindow.DisplayGridlines=false;//不显示网格线
sheets.DisplayAutomaticPageBreaks=true;//显示分页线
sheets.PageSetup.CenterFooter = "第 &P 页,共 &N 页";
sheets.PageSetup.TopMargin=exce.InchesToPoints(0.590551181102362);//上1.5
sheets.PageSetup.BottomMargin=exce.InchesToPoints(0.590551181102362);//下1.5
sheets.PageSetup.LeftMargin=exce.InchesToPoints(0.78740157480315);//左边距2
sheets.PageSetup.RightMargin=exce.InchesToPoints(0.393700787401575);//右边距1
sheets.PageSetup.HeaderMargin=exce.InchesToPoints(0.393700787401575);//页眉1
sheets.PageSetup.FooterMargin=exce.InchesToPoints(0.393700787401575);//页脚1
sheets.PageSetup.CenterHorizontally=true;//水平居中
sheets.PageSetup.PrintTitleRows = "$1:$3";//顶端标题行
sheets.PageSetup.PaperSize=Excel.XlPaperSize.xlPaperA3;//.xlPaperB4;//纸张大小
sheets.PageSetup.Orientation=Excel.XlPageOrientation.xlLandscape;//纸张方向.横向
c#的excel边距设置
最新推荐文章于 2024-10-12 16:13:55 发布