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
Goran Bibic
482
2.9k
197k
Export to excel c#
Dec 7 2019 1:56 AM
Need to export to excel, on older version excel work on 2019 dont work
I use this code
try
{
Microsoft.Office.Interop.Excel.Application excel =
new
Microsoft.Office.Interop.Excel.Application();
excel.Visible =
true
;
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Add(System.Reflection.Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1];
int
StartCol = 1;
int
StartRow = 1;
int
j = 0, i = 0;
//Write Headers
for
(j = 0; j < (IOSDataGridView.Columns.Count - 1); j++)
{
// if (j == 0 || j == 1 || j == 5 || j == 7 || j == 12)
if
(j == 0)
{
}
else
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow, StartCol + j];
myRange.Value2 = IOSDataGridView.Columns[j].HeaderText;
}
}
StartRow++;
//Write datagridview content
for
(i = 0; i < IOSDataGridView.Rows.Count; i++)
{
for
(j = 0; j < (IOSDataGridView.Columns.Count - 1); j++)
{
try
{
// if (j == 0 || j == 1 || j == 5 || j == 7 || j == 12)
if
(j == 0)
{
}
else
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow + i, StartCol + j];
myRange.Value2 = IOSDataGridView[j, i].Value ==
null
?
""
: IOSDataGridView[j, i].Value;
}
}
catch
{
;
}
}
}
}
catch
(Exception ex)
{
MessageBox.Show(ex.ToString());
}
Reply
Answers (
2
)
Jquery ajax call in one domain,image saving in other domain
The type initializer for filepath threw an exception.