owc10导出excell

 public static bool ExportForData(System.Data.DataTable[] arr, string fileName, bool isShowExcle)
        {
      
            OWC10.SpreadsheetClass oSheet = new OWC10.SpreadsheetClass();
          
            OWC10.Workbook book = oSheet.ActiveWorkbook;
            OWC10.Worksheets sheets = book.Worksheets;

        
            int arrLen = arr.Length;
            for (int i = 0; i < arrLen; i++) {
                System.Data.DataTable dt = arr[i];
                OWC10.Worksheet worksheet = (OWC10.Worksheet)sheets.Add(Missing.Value, Missing.Value, 1, Missing.Value);
                if (worksheet == null) {
                    return false;
                }
                //worksheet.Name = dt.TableName;
                worksheet.Name = arr[i].TableName;

                //标题
                int cl = 0;
                System.Data.DataColumnCollection dcc = dt.Columns;

                foreach (System.Data.DataColumn dc in dcc) {
                    worksheet.Cells[1, 1 + cl] = dc.Caption;
                    if (dc.Caption.Equals("允许空") || dc.Caption.Equals("主键") || dc.Caption.Equals("外键") || dc.Caption.Equals("是否标志") || dc.Caption.Equals("是否公式")) {
                        worksheet.get_Range(worksheet.Cells[1, 1 + cl], worksheet.Cells[1, 1 + cl]).set_ColumnWidth(8);
                    }
                    else {
                        worksheet.get_Range(worksheet.Cells[1, 1 + cl], worksheet.Cells[1, 1 + cl]).set_ColumnWidth(11);
                    }
                   
                    cl++;
                }
             
               
                worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, dt.Columns.Count]).Font.set_Bold(true);
                worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, dt.Columns.Count]).Interior.set_ColorIndex(15);//背景色设置


                //数据
                int rowCount = dt.Rows.Count;
                int colCount = dt.Columns.Count;
                for (int r = 0; r < rowCount; r++) {
                    for (int l = 0; l < colCount; l++) {
                    
                        if (dt.Rows[r][l].ToString().ToLower().Equals("false")) {
                            worksheet.Cells[r + 2, l + 1] = "否";
                        }
                        else if (dt.Rows[r][l].ToString().ToLower().Equals("true")) {
                            worksheet.Cells[r + 2, l + 1] = "是";
                        }
                        else {

                            worksheet.Cells[r + 2, l + 1] = dt.Rows[r][l].ToString();
                        }
                     
                    }

                }
                worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[dt.Rows.Count + 1, dt.Columns.Count]).Borders.set_LineStyle(OWC10.XlLineStyle.xlContinuous);
               
            }

            oSheet.Export(fileName, OWC10.SheetExportActionEnum.ssExportActionOpenInExcel, OWC10.SheetExportFormat.ssExportAsAppropriate);
            return true;
          

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值