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
Chiquaqua
NA
1
19.8k
How to add new column to existing excel sheet using C#
May 3 2012 4:31 PM
Hello,
I have an excel sheet. How can I append new columns to the end of that sheet using C#.
Please help.
Here is my code
public void AddColumn(string sheetName, string strConn)
{
try
{
OleDbConnection oledbConn = new OleDbConnection(strConn);
oledbConn.Open();
string strQuery = string.Format("SELECT * FROM [" + sheetName + "]", oledbConn);
OleDbDataAdapter oledbDA = new OleDbDataAdapter(strQuery, strConn);
DataSet DS = new DataSet();
oledbDA.Fill(DS);
//add column to excel
xlWorkBook = new Excel.Workbook();
xlWorkSheet = new Excel.Worksheet();
xlSheets = xlWorkBook.Worksheets;
int lastRow = xlWorkSheet.Rows.CurrentRegion.Count;
xlApp = new Excel.Application();
xlWorkSheet = new Excel.Worksheet();
xlWorkSheet.get_Range(xlWorkSheet.Cells[1, 1],xlWorkSheet.Cells[xlWorkSheet.Rows.Count, 1]).Insert(System.Reflection.Missing.Value, Excel.XlInsertShiftDirection.xlShiftToRight);
//DataColumn addColumn = new DataColumn();
//addColumn.DataType = System.Type.GetType("System.String");
//addColumn.ColumnName = "Test";
//addColumn.ReadOnly = true;
//addColumn.AllowDBNull = true;
//DS.Tables[0].Columns.Add(addColumn);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Reply
Answers (
1
)
select special row and column in c#
How to use button in Griedview?