来自HRESULT的异常:0x800A03EC将Datagridveiw导出为ex​​cel时

时间:2015-06-23 06:42:30

标签: c# excel datagridview

请帮我解决这个问题。

if (dataGridViewAssets.Rows.Count > 0)
        {
            copyAlltoClipboard();
            Microsoft.Office.Interop.Excel.Application xlexcel;
            Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;
            xlexcel = new Microsoft.Office.Interop.Excel.Application();
            xlexcel.Visible = true;
            xlWorkBook = xlexcel.Workbooks.Add(misValue); 
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1];
            CR.Select();
            xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
        }      

我收到错误

  

HRESULT的异常:0x800A03EC

从这一行开始:xlWorkBook = xlexcel.Workbooks.Add(misValue);

0 个答案:

没有答案