1. 开发环境visual studio 2010
2. office 2007
代码:
1.任务窗体
代码:
partial class ActionsPaneControl1 : UserControl
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataTable dm = new System.Data.DataTable();
ufsea.SEAOrganizationService service = new ufsea.SEAOrganizationService();
public ActionsPaneControl1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns = false;
dt = CusdbCommon.XMLHelper.XmlDeserializeUnicode(service.GetCorporationListOfGuFen());
dataGridView1.DataSource = dt;
}
private void button3_Click(object sender, EventArgs e)
{
Worksheet workbook = (Worksheet)Globals.ThisWorkbook.Worksheets[1];
DataGridViewSelectedRowCollection selectlist = dataGridView1.SelectedRows;
int counts = selectlist.Count;
List<OrgInfo> list = new List<OrgInfo>();
foreach (DataGridViewRow item in selectlist)
{
OrgInfo data = new OrgInfo();
data.name = item.Cells[1].Value.ToString();
data.area= item.Cells[2].Value.ToString();
data.code = item.Cells[3].Value.ToString();
list.Add(data);
}
Globals.Sheet1.list1.DataSource = list;
}
private void button4_Click(object sender, EventArgs e)
{
Worksheet workbook = (Worksheet)Globals.ThisWorkbook.Worksheets[1];
DataGridViewSelectedRowCollection selectlist = dataGridView1.SelectedRows;
int counts = selectlist.Count;
int index = 4;
foreach (DataGridViewRow item in selectlist)
{
Range myRange = (Microsoft.Office.Interop.Excel.Range)workbook.Cells[index, 3];
myRange.Value = item.Cells[1].Value.ToString();
Range myRange1 = (Microsoft.Office.Interop.Excel.Range)workbook.Cells[index, 4];
myRange1.Value = item.Cells[2].Value.ToString();
Range myRange2 = (Microsoft.Office.Interop.Excel.Range)workbook.Cells[index, 5];
myRange2.Value = item.Cells[3].Value.ToString();
index++;
}
}
}
2. excel 页面控件
3. 测试结果页面: