TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed salah
NA
530
148.7k
How to create Excel file 31055.xlsx in application path
Jan 23 2017 6:55 PM
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();
}
}
Reply
Answers (
1
)
How to add Item to a list in c#?
How to return a value from a class file in c#?