Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Exception from HRESULT: 0x800A03EC - COM Exception Unhandled

Hi,

I am working on exporting data from a dataset to excel. When I used save
file dialog to save the file in a desired path I came across this Error.

Please find below the code I have used

using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace EXPORT_DATASET_EXCEL_II
{
static class ExportingCellByCellMethod
{

public static void ExportToExcel(DataSet dataSet, string outputPath)
// public static void ExportToExcel(DataSet dataSet)
{

// Create the Excel Application object
ApplicationClass excelApp = new ApplicationClass();
//excelApp.Interactive = false;
// Create a new Excel Workbook
Workbook excelWorkbook = excelApp.Workbooks.Add(Type.Missing);

int sheetIndex = 0;

// Copy each DataTable as a new Sheet
foreach (System.Data.DataTable dt in dataSet.Tables)
{

// Create a new Sheet
Worksheet excelSheet = (Worksheet)excelWorkbook.Sheets.Add(
excelWorkbook.Sheets.get_Item(++sheetIndex),
Type.Missing, 1, XlSheetType.xlWorksheet);

excelSheet.Name = dt.TableName;


// Copy the column names (cell-by-cell)
for (int col = 0; col < dt.Columns.Count; col++)
{
excelSheet.Cells[1, col + 1] = dt.Columns[col].ColumnName;
}



// Copy the values (cell-by-cell)
for (int col = 0; col < dt.Columns.Count; col++)
{
for (int row = 0; row < dt.Rows.Count; row++)
{
excelSheet.Cells[row + 2, col + 1] =
dt.Rows[row].ItemArray[col];
((Range)excelSheet.Rows[1,
Type.Missing]).AutoFit();
}

((Range)excelSheet.Columns[1,
Type.Missing]).AutoFit();
((Range)excelSheet.Columns[2,
Type.Missing]).AutoFit();
((Range)excelSheet.Columns[3,
Type.Missing]).AutoFit();

}

}


// Save and Close the Workbook

excelWorkbook.SaveAs(outputPath,
XlFileFormat.xlWorkbookNormal, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
excelWorkbook.Close(true, Type.Missing, Type.Missing);


excelWorkbook = null;

// Release the Application object
excelApp.Quit();
excelApp = null;

// Collect the unreferenced objects
GC.Collect();
GC.WaitForPendingFinalizers();

}

}

}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;

namespace EXPORT_DATASET_EXCEL_II
{
public partial class Form1 : Form
{
System.Data.OleDb.OleDbConnection conn;
OleDbDataAdapter DA;
string S;
DataSet source;

public Form1()
{
InitializeComponent();
conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["MSAccess"].ToString();
}

private DataSet getDemoDataSet()
{
S = "Select Emp_ID as [ID], Emp_Name as NAME,Reason as REASON,
Submitted_Date as [SUBMITTED DATE] from LEAVEMASTER_TABLE";
source = new DataSet();
DA = new OleDbDataAdapter(S, conn);
DA.Fill(source);
source.Tables[0].TableName = "sample";
return source;
}

private void button2_Click(object sender, EventArgs e)
{
DataSet demoDataSet = this.getDemoDataSet();
string savepath;
saveFileDialog1 = new SaveFileDialog();
savepath = saveFileDialog1.FileName + ".xls";
saveFileDialog1.Filter = "xls files (*.xls)|*.xls";

if (saveFileDialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length 0)
{
ExportingCellByCellMethod.ExportToExcel(demoDataSe t,
savepath);

}


MessageBox.Show("Data Exported successfully");


}
}
}


Can anyone help me out in solving this? Replies are highly appreciated. TIA.
--
Regards,
Karthik
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Exception from HRESULT: 0x800A03EC - COM Exception Unhandled

Is it possible you're trying to overwrite an existing file and you're getting
an error from that?

"Karthizen" wrote:

Hi,

I am working on exporting data from a dataset to excel. When I used save
file dialog to save the file in a desired path I came across this Error.

Please find below the code I have used

using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace EXPORT_DATASET_EXCEL_II
{
static class ExportingCellByCellMethod
{

public static void ExportToExcel(DataSet dataSet, string outputPath)
// public static void ExportToExcel(DataSet dataSet)
{

// Create the Excel Application object
ApplicationClass excelApp = new ApplicationClass();
//excelApp.Interactive = false;
// Create a new Excel Workbook
Workbook excelWorkbook = excelApp.Workbooks.Add(Type.Missing);

int sheetIndex = 0;

// Copy each DataTable as a new Sheet
foreach (System.Data.DataTable dt in dataSet.Tables)
{

// Create a new Sheet
Worksheet excelSheet = (Worksheet)excelWorkbook.Sheets.Add(
excelWorkbook.Sheets.get_Item(++sheetIndex),
Type.Missing, 1, XlSheetType.xlWorksheet);

excelSheet.Name = dt.TableName;


// Copy the column names (cell-by-cell)
for (int col = 0; col < dt.Columns.Count; col++)
{
excelSheet.Cells[1, col + 1] = dt.Columns[col].ColumnName;
}



// Copy the values (cell-by-cell)
for (int col = 0; col < dt.Columns.Count; col++)
{
for (int row = 0; row < dt.Rows.Count; row++)
{
excelSheet.Cells[row + 2, col + 1] =
dt.Rows[row].ItemArray[col];
((Range)excelSheet.Rows[1,
Type.Missing]).AutoFit();
}

((Range)excelSheet.Columns[1,
Type.Missing]).AutoFit();
((Range)excelSheet.Columns[2,
Type.Missing]).AutoFit();
((Range)excelSheet.Columns[3,
Type.Missing]).AutoFit();

}

}


// Save and Close the Workbook

excelWorkbook.SaveAs(outputPath,
XlFileFormat.xlWorkbookNormal, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
excelWorkbook.Close(true, Type.Missing, Type.Missing);


excelWorkbook = null;

// Release the Application object
excelApp.Quit();
excelApp = null;

// Collect the unreferenced objects
GC.Collect();
GC.WaitForPendingFinalizers();

}

}

}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;

namespace EXPORT_DATASET_EXCEL_II
{
public partial class Form1 : Form
{
System.Data.OleDb.OleDbConnection conn;
OleDbDataAdapter DA;
string S;
DataSet source;

public Form1()
{
InitializeComponent();
conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["MSAccess"].ToString();
}

private DataSet getDemoDataSet()
{
S = "Select Emp_ID as [ID], Emp_Name as NAME,Reason as REASON,
Submitted_Date as [SUBMITTED DATE] from LEAVEMASTER_TABLE";
source = new DataSet();
DA = new OleDbDataAdapter(S, conn);
DA.Fill(source);
source.Tables[0].TableName = "sample";
return source;
}

private void button2_Click(object sender, EventArgs e)
{
DataSet demoDataSet = this.getDemoDataSet();
string savepath;
saveFileDialog1 = new SaveFileDialog();
savepath = saveFileDialog1.FileName + ".xls";
saveFileDialog1.Filter = "xls files (*.xls)|*.xls";

if (saveFileDialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length 0)
{
ExportingCellByCellMethod.ExportToExcel(demoDataSe t,
savepath);

}


MessageBox.Show("Data Exported successfully");


}
}
}


Can anyone help me out in solving this? Replies are highly appreciated. TIA.
--
Regards,
Karthik

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Exception from HRESULT: 0x800A03EC - COM Exception Unhandled

Thank you Barb for your reply. Well, I tried to overwrite an existing file &
also tried to save it as a new file. However in both cases I was getting
that Exception. It would be wonderful if you could help me out to solve this
issue.
--
Regards,
Karthik


"Barb Reinhardt" wrote:

Is it possible you're trying to overwrite an existing file and you're getting
an error from that?

"Karthizen" wrote:

Hi,

I am working on exporting data from a dataset to excel. When I used save
file dialog to save the file in a desired path I came across this Error.

Please find below the code I have used

using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace EXPORT_DATASET_EXCEL_II
{
static class ExportingCellByCellMethod
{

public static void ExportToExcel(DataSet dataSet, string outputPath)
// public static void ExportToExcel(DataSet dataSet)
{

// Create the Excel Application object
ApplicationClass excelApp = new ApplicationClass();
//excelApp.Interactive = false;
// Create a new Excel Workbook
Workbook excelWorkbook = excelApp.Workbooks.Add(Type.Missing);

int sheetIndex = 0;

// Copy each DataTable as a new Sheet
foreach (System.Data.DataTable dt in dataSet.Tables)
{

// Create a new Sheet
Worksheet excelSheet = (Worksheet)excelWorkbook.Sheets.Add(
excelWorkbook.Sheets.get_Item(++sheetIndex),
Type.Missing, 1, XlSheetType.xlWorksheet);

excelSheet.Name = dt.TableName;


// Copy the column names (cell-by-cell)
for (int col = 0; col < dt.Columns.Count; col++)
{
excelSheet.Cells[1, col + 1] = dt.Columns[col].ColumnName;
}



// Copy the values (cell-by-cell)
for (int col = 0; col < dt.Columns.Count; col++)
{
for (int row = 0; row < dt.Rows.Count; row++)
{
excelSheet.Cells[row + 2, col + 1] =
dt.Rows[row].ItemArray[col];
((Range)excelSheet.Rows[1,
Type.Missing]).AutoFit();
}

((Range)excelSheet.Columns[1,
Type.Missing]).AutoFit();
((Range)excelSheet.Columns[2,
Type.Missing]).AutoFit();
((Range)excelSheet.Columns[3,
Type.Missing]).AutoFit();

}

}


// Save and Close the Workbook

excelWorkbook.SaveAs(outputPath,
XlFileFormat.xlWorkbookNormal, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
excelWorkbook.Close(true, Type.Missing, Type.Missing);


excelWorkbook = null;

// Release the Application object
excelApp.Quit();
excelApp = null;

// Collect the unreferenced objects
GC.Collect();
GC.WaitForPendingFinalizers();

}

}

}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;

namespace EXPORT_DATASET_EXCEL_II
{
public partial class Form1 : Form
{
System.Data.OleDb.OleDbConnection conn;
OleDbDataAdapter DA;
string S;
DataSet source;

public Form1()
{
InitializeComponent();
conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["MSAccess"].ToString();
}

private DataSet getDemoDataSet()
{
S = "Select Emp_ID as [ID], Emp_Name as NAME,Reason as REASON,
Submitted_Date as [SUBMITTED DATE] from LEAVEMASTER_TABLE";
source = new DataSet();
DA = new OleDbDataAdapter(S, conn);
DA.Fill(source);
source.Tables[0].TableName = "sample";
return source;
}

private void button2_Click(object sender, EventArgs e)
{
DataSet demoDataSet = this.getDemoDataSet();
string savepath;
saveFileDialog1 = new SaveFileDialog();
savepath = saveFileDialog1.FileName + ".xls";
saveFileDialog1.Filter = "xls files (*.xls)|*.xls";

if (saveFileDialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length 0)
{
ExportingCellByCellMethod.ExportToExcel(demoDataSe t,
savepath);

}


MessageBox.Show("Data Exported successfully");


}
}
}


Can anyone help me out in solving this? Replies are highly appreciated. TIA.
--
Regards,
Karthik

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Exception from HRESULT: 0x800A03EC - COM Exception Unhandled

Any one there to give a solution?
--
Regards,
Karthik


"Karthizen" wrote:

Thank you Barb for your reply. Well, I tried to overwrite an existing file &
also tried to save it as a new file. However in both cases I was getting
that Exception. It would be wonderful if you could help me out to solve this
issue.
--
Regards,
Karthik


"Barb Reinhardt" wrote:

Is it possible you're trying to overwrite an existing file and you're getting
an error from that?

"Karthizen" wrote:

Hi,

I am working on exporting data from a dataset to excel. When I used save
file dialog to save the file in a desired path I came across this Error.

Please find below the code I have used

using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace EXPORT_DATASET_EXCEL_II
{
static class ExportingCellByCellMethod
{

public static void ExportToExcel(DataSet dataSet, string outputPath)
// public static void ExportToExcel(DataSet dataSet)
{

// Create the Excel Application object
ApplicationClass excelApp = new ApplicationClass();
//excelApp.Interactive = false;
// Create a new Excel Workbook
Workbook excelWorkbook = excelApp.Workbooks.Add(Type.Missing);

int sheetIndex = 0;

// Copy each DataTable as a new Sheet
foreach (System.Data.DataTable dt in dataSet.Tables)
{

// Create a new Sheet
Worksheet excelSheet = (Worksheet)excelWorkbook.Sheets.Add(
excelWorkbook.Sheets.get_Item(++sheetIndex),
Type.Missing, 1, XlSheetType.xlWorksheet);

excelSheet.Name = dt.TableName;


// Copy the column names (cell-by-cell)
for (int col = 0; col < dt.Columns.Count; col++)
{
excelSheet.Cells[1, col + 1] = dt.Columns[col].ColumnName;
}



// Copy the values (cell-by-cell)
for (int col = 0; col < dt.Columns.Count; col++)
{
for (int row = 0; row < dt.Rows.Count; row++)
{
excelSheet.Cells[row + 2, col + 1] =
dt.Rows[row].ItemArray[col];
((Range)excelSheet.Rows[1,
Type.Missing]).AutoFit();
}

((Range)excelSheet.Columns[1,
Type.Missing]).AutoFit();
((Range)excelSheet.Columns[2,
Type.Missing]).AutoFit();
((Range)excelSheet.Columns[3,
Type.Missing]).AutoFit();

}

}


// Save and Close the Workbook

excelWorkbook.SaveAs(outputPath,
XlFileFormat.xlWorkbookNormal, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
excelWorkbook.Close(true, Type.Missing, Type.Missing);


excelWorkbook = null;

// Release the Application object
excelApp.Quit();
excelApp = null;

// Collect the unreferenced objects
GC.Collect();
GC.WaitForPendingFinalizers();

}

}

}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;

namespace EXPORT_DATASET_EXCEL_II
{
public partial class Form1 : Form
{
System.Data.OleDb.OleDbConnection conn;
OleDbDataAdapter DA;
string S;
DataSet source;

public Form1()
{
InitializeComponent();
conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["MSAccess"].ToString();
}

private DataSet getDemoDataSet()
{
S = "Select Emp_ID as [ID], Emp_Name as NAME,Reason as REASON,
Submitted_Date as [SUBMITTED DATE] from LEAVEMASTER_TABLE";
source = new DataSet();
DA = new OleDbDataAdapter(S, conn);
DA.Fill(source);
source.Tables[0].TableName = "sample";
return source;
}

private void button2_Click(object sender, EventArgs e)
{
DataSet demoDataSet = this.getDemoDataSet();
string savepath;
saveFileDialog1 = new SaveFileDialog();
savepath = saveFileDialog1.FileName + ".xls";
saveFileDialog1.Filter = "xls files (*.xls)|*.xls";

if (saveFileDialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length 0)
{
ExportingCellByCellMethod.ExportToExcel(demoDataSe t,
savepath);

}


MessageBox.Show("Data Exported successfully");


}
}
}


Can anyone help me out in solving this? Replies are highly appreciated. TIA.
--
Regards,
Karthik

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Exception from HRESULT: 0x800A03EC Steve C Excel Programming 10 March 20th 08 12:05 PM
Exception from HRESULT: 0x800A03EC Samir1014 Excel Programming 2 September 13th 07 07:14 PM
Exception from HRESULT: 0x800A03EC While opening Workbook Shreyash Excel Programming 0 February 7th 07 09:36 AM
Exception from HRESULT: 0x800A03EC nano2k New Users to Excel 0 July 21st 06 12:15 PM
Chart.Export throws COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC. Steven Excel Programming 1 November 5th 03 06:59 PM


All times are GMT +1. The time now is 08:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"