Merging Cells in Excel using C#

后端 未结 11 1061
耶瑟儿~
耶瑟儿~ 2020-12-24 01:32

I have a database which contains 5 tables. Each table contains 24 rows and each row contains 4 columns.

I want to display these records in Excel sheet. The heading o

相关标签:
11条回答
  • 2020-12-24 02:16
    Worksheet["YourRange"].Merge();
    
    0 讨论(0)
  • 2020-12-24 02:18
    oSheet.get_Range("A1", "AS1").Merge();
    
    0 讨论(0)
  • 2020-12-24 02:18

    Code Snippet

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        private Excel.Application excelApp = null;
        private void button1_Click(object sender, EventArgs e)
        {
            excelApp.get_Range("A1:A360,B1:E1", Type.Missing).Merge(Type.Missing);
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            excelApp = Marshal.GetActiveObject("Excel.Application") as Excel.Application ;
        }
    }
    

    Thanks

    0 讨论(0)
  • 2020-12-24 02:18

    Try it.

    ws.Range("A1:F2").Merge();
    
    0 讨论(0)
  • 2020-12-24 02:18
    using Excel = Microsoft.Office.Interop.Excel;
    // Your code...
    yourWorksheet.Range[yourWorksheet.Cells[rowBegin,colBegin], yourWorksheet.Cells[yourWorksheet.rowEnd, colEnd]].Merge();
    

    Row and Col start at 1.

    0 讨论(0)
提交回复
热议问题