简体   繁体   English

如何使用C#在DataGridView中设置标题和合并单元格?

[英]How to set header and merge cells in DataGridView using C#?

I want to merge cell in a header which I want to set on top of the column name in DataGridView and Header should be in center format. 我想将单元格合并到要设置在DataGridView列名顶部的标题中,并且Header应该为中心格式。 Just like, I had shown the sample in the image. 就像我在图像中显示了样本一样。

样品

I tried some code from this link but it didn't work for me. 我从此链接尝试了一些代码,但对我而言不起作用。

This code may help you.. 此代码可能会帮助您。

        wBook = _excel.Workbooks.Add()
        wSheet = wBook.ActiveSheet()
        wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).Merge()
            wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).WrapText = True
            wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).Font.Bold = True
            wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).Borders.LineStyle = 1

            wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).HorizontalAlignment = Excel.Constants.xlCenter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM