引用COM.Excel.dll创建XLS文件

static void Main(string[] args)
  {
   COM.Excel.cExcelFile excel = new COM.Excel.cExcelFile();
   excel.CreateFile("c://test.xls");
            excel.PrintGridLines = false;

   COM.Excel.cExcelFile.MarginTypes mt1 = COM.Excel.cExcelFile.MarginTypes.xlsTopMargin;
   COM.Excel.cExcelFile.MarginTypes mt2 = COM.Excel.cExcelFile.MarginTypes.xlsLeftMargin;
   COM.Excel.cExcelFile.MarginTypes mt3 = COM.Excel.cExcelFile.MarginTypes.xlsRightMargin;
   COM.Excel.cExcelFile.MarginTypes mt4 = COM.Excel.cExcelFile.MarginTypes.xlsBottomMargin;
   double height = 1.5;
            excel.SetMargin(ref mt1, ref height);
            excel.SetMargin(ref mt2, ref height);
   excel.SetMargin(ref mt3, ref height);
   excel.SetMargin(ref mt4, ref height);

   COM.Excel.cExcelFile.FontFormatting ff = COM.Excel.cExcelFile.FontFormatting.xlsItalic;
   string font = "Arial";
   short fontsize = 12;
            excel.SetFont(ref font, ref fontsize,ref ff);

   byte b1 = 1,b2 = 12;
   short s3 = 18;
            excel.SetColumnWidth(ref b1,ref b2,ref s3);

   string header = "头";
   string footer = "角";
            excel.SetHeader(ref header);
           excel .SetFooter(ref footer);

   COM.Excel.cExcelFile.ValueTypes vt = COM.Excel.cExcelFile.ValueTypes.xlsText;
   COM.Excel.cExcelFile.CellFont cf = COM.Excel.cExcelFile.CellFont.xlsFont0;
   COM.Excel.cExcelFile.CellAlignment ca = COM.Excel.cExcelFile.CellAlignment.xlsLeftAlign;
   COM.Excel.cExcelFile.CellHiddenLocked chl = COM.Excel.cExcelFile.CellHiddenLocked.xlsNormal;
   int row = 1,col = 1,cellformat = 0;
   object title = "没有使用任何EXCEL组件,直接写成了一个EXCEL文件,cool吧?!";
            excel.WriteValue(ref vt, ref cf, ref ca, ref chl,ref row,ref col,ref title,ref cellformat);

   int ret = excel.CloseFile();
   if(ret!=0)
   {
    Console.WriteLine("Error!");
   }
   else
   {
    Console.WriteLine("请打开文件c://test.xls!");
   }
  }

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值