Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
How to create Excel file 31055.xlsx in application path
ahmed salah
Jan 23 2017 6:55 PM
250
Reply
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();
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to add Item to a list in c#?
How to return a value from a class file in c#?