Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export datagridview to excel 2013

Status
Not open for further replies.

orent

Programmer
Dec 9, 2003
2
0
0
IL
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;
}
}
 
 http://files.engineering.com/getfile.aspx?folder=207bbbd8-f4fa-49d9-9781-4132ab6a8d32&file=Untitled.png
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top