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
SADAM HUSSAIN
NA
65
4.2k
How to export my Grid to Excel with Password proteced
Dec 2 2016 5:58 AM
I have a code but got error.plz help me
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int CCol = 1;
for (int j = 1; j <= dgcBankSetup.Columns.Count; j++)
{
xlWorkSheet.Cells[1, CCol] = dgcBankSetup.Columns[j].Header;
xlWorkSheet.Cells[1, CCol].ColumnWidth = dgcBankSetup.Columns[j].Width;
xlWorkSheet.Cells[1, CCol].Font.Bold = true;
CCol = CCol + 1;
}
foreach (DataRowView i in dgcBankSetup.ItemsSource)
{
DataRow DR = i.Row;
CCol = 1;
for (int j = 1; j <= dgcBankSetup.Columns.Count; j++)
{
xlWorkSheet.Cells[i, CCol].value = dgcBankSetup.rows
//gcBankSetup.SelectAllCells();
CCol = CCol + 1;
}
}
xlWorkSheet.Cells.Borders.LineStyle = 1;
xlWorkBook.SaveAs(SaveDialogBox.FileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
Reply
Answers (
4
)
WPF: how to create a menu dinamically using MVVM
How to import Excel with Password proteced file to Datagrid