如何使用visual c#从excel到windows窗体的列表框中获取A,B,C等列标题名称# [英] how to fetch column header names like A,B,C...from excel to listbox of windows form by using visual c#

查看:231
本文介绍了如何使用visual c#从excel到windows窗体的列表框中获取A,B,C等列标题名称#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在开发一个excel插件,其中我有一个窗口表单,其中包含列表框和一个按钮。我想获取活动表格的excel列标题,如A,B,C等。在列表框中单击按钮上的完整列值。我搜索了很多,但没有找到任何东西。我正在使用visual studio 2010(visual c#)我会非常感谢任何帮助。

解决方案

有一个看看这个



http://www.aspforums.net/Threads/505299/Read-the-Column-Values-of-the-Header-Row- in-Excel-2003-and-2007-file-C /


我已经解决了它我自己。



 Microsoft.Office.Interop.Excel.Worksheet activeSheet = 
(Microsoft.Office.Interop.Excel。工作表)Globals.ThisAddIn.Application.ActiveSheet;




如果从组合框中使用,则需要




 Excel.Range rng = activeSheet.UsedRange.Columns [  + comboBox2.SelectedItem + < span class =code-string> ,System.Type.Missing]; 

rng.Select();







 Excel.Range rng = activeSheet.UsedRange.Columns [  A,System.Type 。失踪]; 

rng.Select();





它适用于我。


hello everyone. I am developing a excel plugin in which i have a window form which contains listbox and a button. I want to fetch excel column headers of activesheet like A,B,C,etc. in the listbox alonwith full column values on button click. I searched a lot on it but did not found anything.I am using visual studio 2010 (visual c#) I will be really thankful for any help.

解决方案

Have a look at this

http://www.aspforums.net/Threads/505299/Read-the-Column-Values-of-the-Header-Row-in-Excel-2003-and-2007-file-C/


i have solved it by myself.

 Microsoft.Office.Interop.Excel.Worksheet activeSheet =
(Microsoft.Office.Interop.Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet; 



if use from combobox then,

Excel.Range rng = activeSheet.UsedRange.Columns["" + comboBox2.SelectedItem + "", System.Type.Missing];
            
rng.Select();


or

Excel.Range rng = activeSheet.UsedRange.Columns["A", System.Type.Missing];
            
rng.Select();



it works fine for me.


这篇关于如何使用visual c#从excel到windows窗体的列表框中获取A,B,C等列标题名称#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆