20c0108c
wutaian
xx
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
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 GeneralLib;
namespace SunVoteARSPPT
{
public partial class FrmImportCandidate : Form
{
//数据开始行
private int StarRowIndex = 1;
//候选人编号列
private int IDColIndex = 0;
//候选人名称列
private int NameColIndex = 1;
private DataGridView dgvVoterList = null;
ExcelOper exl = new ExcelOper();
public FrmImportCandidate(DataGridView dgv)
{
InitializeComponent();
dgvVoterList = dgv;
}
private void lblCandidateName_Click(object sender, EventArgs e)
{
}
private void btnOK_Click(object sender, EventArgs e)
{
if (txtFileName.Text == "") { MessageBox.Show("请选择导入文件", GlobalInfo.GetAppName()); btnFile.Focus() ; return; }
if (cobCandidateID.Text == "") { MessageBox.Show("请选择候选人编号对应的列", GlobalInfo.GetAppName()); cobCandidateID.Focus(); return; }
if (cobCandidateName.Text == "") { MessageBox.Show("请选择候选人名称对应的列", GlobalInfo.GetAppName()); cobCandidateName.Focus(); return; }
string fileName = "";
string[,] PollList;
//openFileDialog.InitialDirectory = "C:\\";
//openFileDialog.Filter = "Execl files (*.xls)|*.xls|Excel files (*.xlsx)|*.xlsx";
//if (openFileDialog.ShowDialog() == DialogResult.OK)
//{
fileName = openFileDialog.FileName;
exl.OpenExcel(fileName);
PollList = exl.ImportToSheetBySheetNum(cobSheet.SelectedIndex + 1);
int iRowCount = PollList.GetLength(0);
int iColCount = PollList.GetLength(1);
dgvVoterList.RowCount = iRowCount;
for (int i = 0; i < iRowCount - 1; i++)
{
dgvVoterList.Rows[i].Cells[0].Value = PollList[i + StarRowIndex, IDColIndex];
dgvVoterList.Rows[i].Cells[1].Value = PollList[i + StarRowIndex, NameColIndex];
}
ControlOper.SetGridRowH(dgvVoterList);//杨斌 2016-03-04
//}
Close();
}
private void btnFile_Click(object sender, EventArgs e)
{
openFileDialog.InitialDirectory = "C:\\";
//openFileDialog.Filter = "Execl files (*.xls)|*.xls|Excel files (*.xlsx)|*.xlsx";
openFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx";//杨斌 2018-12-18。不兼容2003格式
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = openFileDialog.FileName;
txtFileName.Text = fileName;
exl.OpenExcel(fileName);
string [] sheetList= exl.ExcelSheetList();
ConvertToComboBox(cobSheet, sheetList);
cobSheet.SelectedIndex = 0;
// string[,] PollList = exl.ImportToSheetBySheetNum(1);
}
}
private void cobSheet_SelectedIndexChanged(object sender, EventArgs e)
{
string[] ColList=null;
if (cobSheet.Text != "")
{
ColList = exl.GetColList(cobSheet.Text);
ConvertToComboBox(cobCandidateID, ColList);
cobCandidateID.SelectedIndex = 0;
ConvertToComboBox(cobCandidateName, ColList);
cobCandidateName.SelectedIndex = 1;
}
}
private void ConvertToComboBox(ComboBox cb, string[] slist)
{
cb.Items.Clear();
for (int i = 0; i < slist.Length; i++)
{
cb.Items.Add(slist[i]);
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void cobCandidateID_SelectedIndexChanged(object sender, EventArgs e)
{
IDColIndex = cobCandidateID.SelectedIndex ;
}
private void cobCandidateName_SelectedIndexChanged(object sender, EventArgs e)
{
NameColIndex = cobCandidateName.SelectedIndex;
}
private void FrmImportCandidate_Load(object sender, EventArgs e)
{
}
}
}
|