winfrom中 listview导出数据到 excel 但是我导出的数据一旦是身份证号以及时间 数据就不对了 谁帮帮?先谢谢了
代码如下:
//按钮
private void button1_Click(object sender, EventArgs e)
{
TurntoExel(listView1,"sheet_1");
}
//导出的方法
public void TurntoExel(ListView listview,string name)
{
if(listView1.Items.Count<0)
{
return;
}
Excel.Application myexcel = new Excel.Application();
myexcel.Visible = true;
myexcel.Caption = "第一章";//excel标题
if(myexcel==null)
{
return;
}
Excel.Workbooks workbooks = (Excel.Workbooks)myexcel.Workbooks;
Excel.Workbook workbook = workbooks.Add(Missing.Value);
Excel.Worksheet sheet = (Excel.Worksheet)workbook.Worksheets[1];
Excel.Range range = sheet.get_Range("A1","H1");
range=range.get_Resize(1, listView1.Columns.Count);
object[] MyHeader = new object[listView1.Columns.Count];//动态获取listview表中的列值
for (int i = 0; i < listView1.Columns.Count; i++)
{
MyHeader.SetValue(listView1.Columns[i].Text, i);
}
range.Value2 = MyHeader;
sheet.Name = name;//设置表名
if (listView1.Items.Count > 0)
{
range = sheet.get_Range("A2", Missing.Value);
object[,] MyData = new Object[listView1.Items.Count, listView1.Columns.Count];
for (int j = 0; j < listView1.Items.Count; j++)