问题:
1.导出Excel,如何让所有单元格的边框都不显示,就像一张白纸一样
2.怎么让某一块区域显示边框
3.怎么设置字体大小和粗细
4.我代码合并单元格之后边框不见了。
如图:

解决方案 »

  1.   

    导出前先弄个Excel模板,把要求的设置都设置好,再导出,用模板导出
      

  2.   

    excel里面有个函数,背景颜色设置白色就是了。
      

  3.   

    //读取数据库,并且导出到Excal
            private void btn_读取数据库_Click(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=MyCinema;Integrated Security=True");
                SqlDataAdapter adapter = new SqlDataAdapter("select * from Movie", con);
                DataSet ds = new DataSet();
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];
                //数据库的数据导入Excal
                Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
                app.Workbooks.Add();
                app.SheetsInNewWorkbook = 1;
                Worksheet w1 = (Worksheet)app.ActiveWorkbook.Worksheets[1];
                w1.Name = "First";
                for (int i = 1; i < dataGridView1.Rows.Count; i++) {
                    for (int j = 1; j < dataGridView1.Rows[i].Cells.Count; j++)
                    {
                        w1.Cells[i, j] = dataGridView1.Rows[i - 1].Cells[j - 1].Value.ToString();
                    }
                }
                //给Excal设置样式,range表示区域,有格式属性,r.NumberFormat = "yyyy-m-d";事件格式
                Range r = app.get_Range(app.Cells[1, 1], app.Cells[17, 5]);
                r.Font.Color = Color.Green;
                r.Borders.LineStyle = XlLineStyle.xlContinuous;            app.Visible = true;
                app.ActiveWorkbook.SaveAs(Environment.CurrentDirectory + "/test.xls", XlFileFormat.xlWorkbookNormal);
            }
      

  4.   

    其中这里是给设置了某个区域内的单元格的样式,更多的希望楼主去看看Range 的属性
      

  5.   

    主要样式设置
              //给Excal设置样式,range表示区域,有格式属性,r.NumberFormat = "yyyy-m-d";事件格式
                Range r = app.get_Range(app.Cells[1, 1], app.Cells[17, 5]);
                 r.Font.Color = Color.Green;
                 r.Borders.LineStyle = XlLineStyle.xlContinuous;
      

  6.   

    我range怎么点不出来,是要导入什么命名空间吗?
      

  7.   

    我range怎么点不出来,是要导入什么命名空间吗?using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.Excel;
    using System.Data.SqlClient;
    using System.Data.OleDb;
      

  8.   

    导出Excel无边框---导出来后设置无边框不行么?
    就是多了一步excel的设置步骤
      

  9.   

    必须用 DCOM 访问方式
    CreateObject("Excel.Application")oledb 什么的,不可能
      

  10.   

    我range怎么点不出来,是要导入什么命名空间吗?using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.Excel;
    using System.Data.SqlClient;
    using System.Data.OleDb;
      Range r = app.get_Range(app.Cells[1, 1], app.Cells[17, 5]);
    这个APP是什么啊?
      

  11.   

      Workbook workbook = new Workbook();
     worksheet.Cells.ImportDataTable(pdt, true, 0, 0, rows, pdt.Columns.Count);                //定义表格的标题
                    worksheet.Cells.InsertRow(0);
                    Range range = worksheet.Cells.CreateRange(worksheet.Cells[0, 0].Name, worksheet.Cells[0, pdt.Columns.Count - 1].Name);
                    range.RowHeight = 20;
                    range.Name = "ExcelTitle";
                    range.Merge();
                    Style style = workbook.Styles[workbook.Styles.Add()];
                    style.Font.Name = "宋体";
                    style.Font.IsBold = true;
                    style.Font.Size = 14;
                    style.HorizontalAlignment = TextAlignmentType.Center;
                    range.Style = style;
                    range[0, 0].PutValue(arrTitle[0]);
      

  12.   

    我range怎么点不出来,是要导入什么命名空间吗?using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.Excel;
    using System.Data.SqlClient;
    using System.Data.OleDb;
      Range r = app.get_Range(app.Cells[1, 1], app.Cells[17, 5]);
    这个APP是什么啊?我range怎么点不出来,是要导入什么命名空间吗?using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.Excel;
    using System.Data.SqlClient;
    using System.Data.OleDb;
      Range r = app.get_Range(app.Cells[1, 1], app.Cells[17, 5]);
    这个APP是什么啊?Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();z这个类