js操作excel

 

 

 

function test(){


 var ExcelSheet; 
 ExcelApp = new ActiveXObject("Excel.Application");
 
 ExcelSheet = new ActiveXObject("Excel.Sheet");
 
 
//  使 Excel 通过 Application 对象可见。  
   ExcelSheet.Application.Visible = true;
  
  
//   ExcelSheet.ActiveSheet.Cells(1,2).Value = "内容";
  
    ExcelApp.Range("A1:D1").MergeCells = true;
    ExcelApp.Range("A2:B7").MergeCells = true;
    ExcelApp.Range("C2:D2").MergeCells = true;
    ExcelApp.Range("C3:D3").MergeCells = true;
    ExcelApp.Range("C4:D4").MergeCells = true;
    ExcelApp.Range("C5:D5").MergeCells = true;
    ExcelApp.Range("C6:D6").MergeCells = true;
    ExcelApp.Range("C7:D7").MergeCells = true;
    ExcelApp.Range("A14:B14").MergeCells = true;
    ExcelApp.Range("C14:D14").MergeCells = true;
    //合并单元格
    ExcelSheet.ActiveSheet.Cells(1,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(1,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(1,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(1,4).Borders.Weight = 2;
   
   
    //设置单元格银颜色
    ExcelSheet.ActiveSheet.Cells(1,1).Interior.ColorIndex = 3;
   
    ExcelSheet.ActiveSheet.Cells(1,1).Value = "员工信息表";
    ExcelSheet.ActiveSheet.Cells(1,1).HorizontalAlignment = 3;
    //字体设置
    ExcelSheet.ActiveSheet.Cells(1,1).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(1,1).Font.Size = 12;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(1,1).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(1,1).Font.Name = "宋体";
   
   
    //设置单元格行高
     ExcelSheet.ActiveSheet.Rows("1:1").RowHeight = 31.8;
    
   
    ExcelSheet.ActiveSheet.Cells(2,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(2,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(2,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(2,4).Borders.Weight = 2;
   
   
    ExcelSheet.ActiveSheet.Cells(2,3).Value = "部门:组装B线";
    ExcelSheet.ActiveSheet.Cells(2,3).HorizontalAlignment = 3;
   
    ExcelSheet.ActiveSheet.Rows("2:2").RowHeight = 18;
    //字体设置
    ExcelSheet.ActiveSheet.Cells(2,3).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(2,3).Font.Size = 10;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(2,3).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(2,3).Font.Name = "宋体";
   
   
   
    ExcelSheet.ActiveSheet.Cells(3,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(3,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(3,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(3,4).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(3,3).Value = "姓名:";
    ExcelSheet.ActiveSheet.Cells(3,3).HorizontalAlignment = 3;
   
   
    //字体设置
    ExcelSheet.ActiveSheet.Cells(3,3).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(3,3).Font.Size = 10;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(3,3).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(3,3).Font.Name = "宋体";
   
    ExcelSheet.ActiveSheet.Cells(4,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(4,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(4,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(4,4).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(4,3).Value = "工号:";
    ExcelSheet.ActiveSheet.Cells(4,3).HorizontalAlignment = 3;

   
    ExcelSheet.ActiveSheet.Rows("3:5").RowHeight = 17.4;
    ExcelSheet.ActiveSheet.Rows("6:6").RowHeight = 15.6;
    ExcelSheet.ActiveSheet.Rows("7:13").RowHeight = 16.2;
    ExcelSheet.ActiveSheet.Rows("14:14").RowHeight = 21;
   
   
    //字体设置
    ExcelSheet.ActiveSheet.Cells(4,3).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(4,3).Font.Size = 10;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(4,3).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(4,3).Font.Name = "宋体";
   
    ExcelSheet.ActiveSheet.Cells(5,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(5,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(5,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(5,4).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(5,3).Value = "入社日:04.11.2";
    ExcelSheet.ActiveSheet.Cells(5,3).HorizontalAlignment = 3;
   
    //字体设置
    ExcelSheet.ActiveSheet.Cells(5,3).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(5,3).Font.Size = 10;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(5,3).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(5,3).Font.Name = "宋体";
   
    ExcelSheet.ActiveSheet.Cells(6,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(6,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(6,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(6,4).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(6,3).Value = "职位:班长";
    ExcelSheet.ActiveSheet.Cells(6,3).HorizontalAlignment = 3;
       
    //字体设置
    ExcelSheet.ActiveSheet.Cells(6,3).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(6,3).Font.Size = 10;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(6,3).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(6,3).Font.Name = "宋体";
   
   
    ExcelSheet.ActiveSheet.Cells(7,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(7,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(7,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(7,4).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(7,3).Value = "技能等级:一级";
    ExcelSheet.ActiveSheet.Cells(7,3).HorizontalAlignment = 3;
   
    //字体设置
    ExcelSheet.ActiveSheet.Cells(7,3).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(7,3).Font.Size = 10;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(7,3).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(7,3).Font.Name = "宋体";
   
    ExcelSheet.ActiveSheet.Cells(8,1).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(8,1).Value = "工程";
    ExcelSheet.ActiveSheet.Cells(8,1).HorizontalAlignment = 3;
       
    //字体设置
    ExcelSheet.ActiveSheet.Cells(8,1).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(8,1).Font.Size = 9;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(8,1).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(8,1).Font.Name = "宋体";
   
    ExcelSheet.ActiveSheet.Cells(8,2).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(8,2).Value = "评价";
    ExcelSheet.ActiveSheet.Cells(8,2).HorizontalAlignment = 3;
       
    //字体设置
    ExcelSheet.ActiveSheet.Cells(8,2).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(8,2).Font.Size = 9;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(8,2).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(8,2).Font.Name = "宋体";
   
    ExcelSheet.ActiveSheet.Cells(8,3).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(8,3).Value = "工程";
    ExcelSheet.ActiveSheet.Cells(8,3).HorizontalAlignment = 3;
   
    //字体设置
    ExcelSheet.ActiveSheet.Cells(8,3).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(8,3).Font.Size = 9;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(8,3).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(8,3).Font.Name = "宋体";
   
    ExcelSheet.ActiveSheet.Cells(8,4).Borders.Weight = 2;
   
    ExcelSheet.ActiveSheet.Cells(8,4).Value = "评价";
    ExcelSheet.ActiveSheet.Cells(8,4).HorizontalAlignment = 3;
       
    //字体设置
    ExcelSheet.ActiveSheet.Cells(8,4).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(8,4).Font.Size = 9;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(8,4).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(8,4).Font.Name = "宋体";
   
    ExcelSheet.ActiveSheet.Cells(9,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(9,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(9,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(9,4).Borders.Weight = 2;
  
    //添加图片
    var msoShaoeRectangle = 1;//AddShape(透明度,左,上,宽度,高度)
    ExcelSheet.ActiveSheet.Shapes.AddShape(msoShaoeRectangle, 70, 155, 7, 7).Fill.UserPicture("C:\\one.jpg");
   
    ExcelSheet.ActiveSheet.Cells(10,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(10,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(10,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(10,4).Borders.Weight = 2;
   
    var msoShaoeRectangle = 1;//AddShape(透明度,左,上,宽度,高度)
    ExcelSheet.ActiveSheet.Shapes.AddShape(msoShaoeRectangle, 70, 171, 7, 7).Fill.UserPicture("C:\\one.jpg");
   
    ExcelSheet.ActiveSheet.Cells(11,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(11,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(11,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(11,4).Borders.Weight = 2;
   
    var msoShaoeRectangle = 1;//AddShape(透明度,左,上,宽度,高度)
    ExcelSheet.ActiveSheet.Shapes.AddShape(msoShaoeRectangle, 70, 187, 7, 7).Fill.UserPicture("C:\\one.jpg");
   
    ExcelSheet.ActiveSheet.Cells(12,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(12,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(12,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(12,4).Borders.Weight = 2;
   
    var msoShaoeRectangle = 1;//AddShape(透明度,左,上,宽度,高度)
    ExcelSheet.ActiveSheet.Shapes.AddShape(msoShaoeRectangle, 70, 203, 7, 7).Fill.UserPicture("C:\\one.jpg");
   
   
    ExcelSheet.ActiveSheet.Cells(13,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(13,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(13,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(13,4).Borders.Weight = 2;
   
    var msoShaoeRectangle = 1;//AddShape(透明度,左,上,宽度,高度)
    ExcelSheet.ActiveSheet.Shapes.AddShape(msoShaoeRectangle, 70, 219, 7, 7).Fill.UserPicture("C:\\one.jpg");
   
    ExcelSheet.ActiveSheet.Cells(14,1).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(14,2).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(14,3).Borders.Weight = 2;
    ExcelSheet.ActiveSheet.Cells(14,4).Borders.Weight = 2;
   
   
    ExcelSheet.ActiveSheet.Cells(14,1).Value = "合格-";
    ExcelSheet.ActiveSheet.Cells(14,1).HorizontalAlignment = 3;
       
   
    //字体设置
    ExcelSheet.ActiveSheet.Cells(14,1).Font.ColorIndex = 1;        //设置字体颜色*(与上相同)  
    ExcelSheet.ActiveSheet.Cells(14,1).Font.Size = 9;                //设置为10号字*  
    ExcelSheet.ActiveSheet.Cells(14,1).Font.Bold = true;  
    ExcelSheet.ActiveSheet.Cells(14,1).Font.Name = "宋体";
   
   
   
   
 
   ExcelSheet.SaveAs("C:\\TEST.XLS");  
   ExcelSheet.Application.Quit(); 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值