本节内容:
使用javascript中ActiveXObject填充并设置Excel格式
1,创建excel工作簿与工作表
2.保存表格
3.使 Excel 通过 Application 对象可见
4.打印
5.关闭
6.结束进程
7.设置行高与列宽
ExcelSheet.ActiveSheet.Columns.ColumnWidth = 22;
//设置从firstcol到stopcol列的宽度为22
ExcelSheet.ActiveSheet.Rows.RowHeight = 22;
//设置从firstrow到stoprow行的宽度为22
8.页面设置
ExcelSheet.ActiveSheet.PageSetup.LeftMargin= 2/0.035;
//页边距 左2厘米
ExcelSheet.ActiveSheet.PageSetup.RightMargin = 3/0.035;
//页边距右3厘米
ExcelSheet.ActiveSheet.PageSetup.TopMargin = 4/0.035;
//页边距上4厘米
ExcelSheet.ActiveSheet.PageSetup.BottomMargin = 5/0.035;
//页边距下5厘米
ExcelSheet.ActiveSheet.PageSetup.HeaderMargin = 1/0.035;
//页边距页眉1厘米
ExcelSheet.ActiveSheet.PageSetup.FooterMargin = 2/0.035;
//页边距页脚2厘米
ExcelSheet.ActiveSheet.PageSetup.CenterHeader = "页眉中部内容";
ExcelSheet.ActiveSheet.PageSetup.LeftHeader = "页眉左部内容";
ExcelSheet.ActiveSheet.PageSetup.RightHeader = "页眉右部内容";
ExcelSheet.ActiveSheet.PageSetup.CenterFooter = "页脚中部内容";
ExcelSheet.ActiveSheet.PageSetup.LeftFooter = "页脚左部内容";
ExcelSheet.ActiveSheet.PageSetup.RightFooter = "页脚右部内容";
9.对单元格操作,带*部分对于行,列,区域都有相应属性
ExcelSheet.ActiveSheet.Cells.Value = "内容";
//设置单元格内容
ExcelSheet.ActiveSheet.Cells.Borders.Weight = 1;
//设置单元格边框*
ExcelSheet.ActiveSheet.Cells.Interior.ColorIndex = 1;
//设置单元格底色*
ExcelSheet.ActiveSheet.Cells.Interior.Pattern = 1;
//设置单元格背景样式*
ExcelSheet.ActiveSheet.Cells.Font.ColorIndex = 1;
//设置字体颜色*
ExcelSheet.ActiveSheet.Cells.Font.Size = 10;
//设置为10号字*
ExcelSheet.ActiveSheet.Cells.Font.Name = "黑体";
//设置为黑体*
ExcelSheet.ActiveSheet.Cells.Font.Italic = true;
//设置为斜体*
ExcelSheet.ActiveSheet.Cells.Font.Bold = true;
//设置为粗体*
ExcelSheet.ActiveSheet.Cells.ClearContents;
//清除内容*
ExcelSheet.ActiveSheet.Cells.WrapText=true;
//设置为自动换行*
ExcelSheet.ActiveSheet.Cells.HorizontalAlignment = 3;
//水平对齐方式枚举*
ExcelSheet.ActiveSheet.Cells.VerticalAlignment = 2;
//垂直对齐方式枚举*
行,列有相应操作:
ExcelSheet.ActiveSheet.Rows.
ExcelSheet.ActiveSheet.Columns.
ExcelSheet.ActiveSheet.Rows.
//如Rows即1到5行
ExcelSheet.ActiveSheet.Columns.
//如Columns即1到5列
区域有相应操作:
XLObj.Range.Select;
//如Range即A列第2格至H列第8格的整个区域
XLObj.Selection.
合并单元格
XLObj.Range.MergeCells = true;
//如Range即将A列第2格至H列第8格的整个区域合并为一个单元格
XLObj.Range).MergeCells = true;