1
Hey Ahmed,
Please review your code and question, as you are asking 'excel file was not created' and in your code, you are returning false, if file doesnot exists
if (!File.Exists(strFilePath)) return false;
Please check the below link for your reference:
http://csharp.net-informations.com/excel/csharp-create-excel.htm
0
Hi, check this link for generating Excel from database.
https://www.e-iceblue.com/Tutorials/Spire.XLS/Spire.XLS-Program-Guide/Data-Export-/Import-Export-Datatable-to-Excel-from-Database.html
-1
my problem only in creating excel so that i try with another way
in the code here excel file created but not open so that can you tell me why not open after created
my code as bellow
- 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:\\Book310.xlsx;Extended Properties=Excel 12.0;";
-
- 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();
- }
- }
after that file 310 created but not open
when open file i get this error
