I work in windows form c# visual studio 2015
I have excel file xlsx and name is 3105.xlsx and i need to create it in application path
how to create excel file in application path
my code
- public void CreateSheetIfNotExists()
- {
- using (System.Data.OleDb.OleDbConnection databaseConnection = new System.Data.OleDb.OleDbConnection())
- {
-
- DataTable schemaTable = default(DataTable);
- databaseConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=D:\\Book3105.xlsx;Mode=ReadWrite;Extended Properties=Excel 12.0 Xml;";
-
- databaseConnection.Open();
-
- schemaTable = databaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] {
- null,
- null,
- "Sheet1$"
- });
-
- if (schemaTable.Rows.Count == 0)
- {
- string SQLDDLCommand = "CREATE TABLE [Sheet1] (UserID INTEGER, UserName CHAR(255))";
- System.Data.OleDb.OleDbCommand excelCommand = new System.Data.OleDb.OleDbCommand(SQLDDLCommand, databaseConnection);
- excelCommand.ExecuteNonQuery();
-
- }
-
- databaseConnection.Close();
- }
- }