on excel 2007 its ok
but on excel2013 its get error:
this is the line error::::
xlWorkBook = xlApp.Workbooks.Add(misValue);
this is the code :
//Excel.ApplicationClass xlApp;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
SaveFileDialog oDialog = new SaveFileDialog();
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
int z = 1;
//button1.Visible = true;
this.Cursor = Cursors.WaitCursor;
///////////////////////////////////////////////////////////////////////
foreach (DataGridViewColumn c in dvRMS.Columns)
{
c.SortMode = DataGridViewColumnSortMode.NotSortable;
c.Selected = false;
}
dvRMS.SelectionMode = DataGridViewSelectionMode.FullColumnSelect;
for (int ii = 0; ii < LSTsegmentTO.Items.Count; ii++)
{
LSTsegmentTO.SetSelected(ii, true);
}
if (cmbReportType.GetItemText(cmbReportType.SelectedItem) == "עברית ואנגלית")
{
// storing header part in Excel
for (int x = 0; x <= LSTsegmentTO.SelectedItems.Count - 1; x++)
{
foreach (DataGridViewColumn column in dvRMS.Columns)
{
DataGridViewColumnHeaderCell headerCell = column.HeaderCell;
string headerCaptionText = column.HeaderText;
string columnName = column.Name; // Used as a key to myDataGridView.Columns['key_name'];
int columnPos = column.Index;
if (columnName == LSTsegmentTO.SelectedItems[x].ToString())
{
dvRMS.Columns[columnPos].Selected = true;
}
}
but on excel2013 its get error:
this is the line error::::
xlWorkBook = xlApp.Workbooks.Add(misValue);
this is the code :
//Excel.ApplicationClass xlApp;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
SaveFileDialog oDialog = new SaveFileDialog();
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
int z = 1;
//button1.Visible = true;
this.Cursor = Cursors.WaitCursor;
///////////////////////////////////////////////////////////////////////
foreach (DataGridViewColumn c in dvRMS.Columns)
{
c.SortMode = DataGridViewColumnSortMode.NotSortable;
c.Selected = false;
}
dvRMS.SelectionMode = DataGridViewSelectionMode.FullColumnSelect;
for (int ii = 0; ii < LSTsegmentTO.Items.Count; ii++)
{
LSTsegmentTO.SetSelected(ii, true);
}
if (cmbReportType.GetItemText(cmbReportType.SelectedItem) == "עברית ואנגלית")
{
// storing header part in Excel
for (int x = 0; x <= LSTsegmentTO.SelectedItems.Count - 1; x++)
{
foreach (DataGridViewColumn column in dvRMS.Columns)
{
DataGridViewColumnHeaderCell headerCell = column.HeaderCell;
string headerCaptionText = column.HeaderText;
string columnName = column.Name; // Used as a key to myDataGridView.Columns['key_name'];
int columnPos = column.Index;
if (columnName == LSTsegmentTO.SelectedItems[x].ToString())
{
dvRMS.Columns[columnPos].Selected = true;
}
}