foreach (Control ctr in this.Controls) { if (ctr is TextBox) { //XXX } }
找到了这些内容后怎样对应的写到excel中呢?
找到了这些内容后怎样写到excel中呢?
Queue<ControlCollection> queue = new Queue<ControlCollection>(); queue.Enqueue(Controls); ControlCollection coll; int i; List<TextBox> lst = new List<TextBox>(); while (queue.Count > 0) { coll = queue.Dequeue(); for (i = 0; i < coll.Count; ++i) { if (coll[i] is TextBox) lst.Add(coll[i] as TextBox); else if(coll[i].Controls.Count > 0) queue.Enqueue(coll[i].Controls); } }
http://blog.csdn.net/jimk5200/article/details/8071729
{
if (ctr is TextBox)
{
//XXX
}
}
queue.Enqueue(Controls);
ControlCollection coll;
int i;
List<TextBox> lst = new List<TextBox>();
while (queue.Count > 0)
{
coll = queue.Dequeue();
for (i = 0; i < coll.Count; ++i)
{
if (coll[i] is TextBox)
lst.Add(coll[i] as TextBox);
else if(coll[i].Controls.Count > 0)
queue.Enqueue(coll[i].Controls);
}
}
第三步就是把数据导入到EXCEL中
http://blog.csdn.net/jimk5200/article/details/6453306
/// 保存excel
/// </summary>
/// <param name="savePath">绝对路径</param>
/// <param name="list">List[string[]]</param>
/// <param name="head">表头</param>
public void Save(string savePath, List<string[]> list, string[] head)
{
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet(sheetName); for (int i = 1; i <= list.Count; i++)
{
for (int j = 0; j < list[i - 1].Length; j++)
{
worksheet.Cells[i, j] = new Cell(TryConvertDate(list[i - 1][j]));
}
} workbook.Worksheets.Add(worksheet);
workbook.Save(savePath);
}
/// <summary>
/// 检查是否日期
/// </summary>
/// <param name="str">验证字符</param>
/// <returns>如果是日期则加上'</returns>
private string TryConvertDate(string str)
{
DateTime date = new DateTime();
if (DateTime.TryParse(str, out date))
{
return "'" + str;
}
return str;
}
http://www.189works.com/article-43508-1.html