c#excel插入检查工作表是否存在
using (DbCommand command = oconn.CreateCommand()) { command.CommandText = "CREATE TABLE [Sheet2$] (F1 number, F2 char(255), F3 char(128))"; command.ExecuteNonQuery(); for (int i = 1; i <= 20; i++) { //now we insert the values into the existing sheet...no new sheet is added. command.CommandText = "INSERT INTO [Sheet2$] (F1, F2, F3) VALUES(1,\"Fake Record\",\"Fake Record\")"; command.ExecuteNonQuery(); } }
我正在使用此代码在Excel文件表中插入一些logging。 我想要做的是看看例如Sheet1是否存在,然后创build工作表2并在那里插入这些logging。 如果它只find工作表3,那么我想要创build另一个工作表4,并在那里插入logging等。 我怎样才能做到这一点?
尝试检查数据模式的表格:
DataTable dtSchema = oconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); DataRow[] dr = dtSchema.Select("TABLE_NAME = 'Sheet1$'"); bool exist = dr == null || dr.Length == 0;
我们可以在这里find相同的解决scheme: https : //mudassarkhan.wordpress.com/tag/c-excel/
- 如何重新创build一个在C#中调用TREND()的Excel公式?
- 从Objective-C(iPhone)的Excel文件读取数据
- 如何从VSTO应用程序插件调用Excel VBA函数
- 使用javascript上传和保存Excel文件C#webservice
- 如何使用.NET更改XLS列数据types
- 为什么Excel.WorkSheet.Copy引发具有HRESULT的types为“System.Runtime.InteropServices.COMException”的第一次机会exception的exception:0x800A03EC
- OpenXML SDK2.5(Excel):如何确定单元格是否包含数值?
- Excel表格validation/公式不被复制到新表格行
- 在由逗号分隔的Excel工作表单元格中为每个值分配variables