INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

export datagridview to excel 2013

export datagridview to excel 2013

(OP)
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;
}
}

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close