将列表写入Xlsx文件时出错

将列表写入Xlsx文件时出错

本文介绍了将列表写入Xlsx文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一些代码,我需要写一个列表<>整数到xlsx文件中.但是出现错误.
这是代码.

OK, I have some code and I need to write a list<> of integers onto an xlsx file. But am getting an error.
Here is the code.

string fileName = @"C:\rhandx.xlsx";
 string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
          fileName + ";Extended Properties=\"Excel 8.0;HDR=NO;\"";
OleDbConnection con = new System.Data.OleDb.OleDbConnection(connectionString);
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
foreach (int coord in rhandlist)
{
    cmd.CommandText = ("INSERT INTO TABLE [SHEET1$] VALUES (coord)");
    cmd.ExecuteNonQuery();
}
con.Close();



rhandlist是一个未知整数的列表.但是我收到一条错误消息,说我的插入语句的语法错误.



rhandlist is a list with unknown no of int''s. But I get an error saying my insert statement''s syntax is wrong.

推荐答案



rhandlist是一个未知整数的列表.但是我收到一条错误消息,指出我的插入语句的语法是错误的.



rhandlist is a list with unknown no of int''s. But I get an error saying my insert statement''s syntax is wrong.


cmd.CommandText = ("INSERT INTO [SHEET1



确保您保持正确的间距.


Make sure you keep the spacing right.


这篇关于将列表写入Xlsx文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 03:04