800A03EC Error excel chart export on second try

  • Thread starter Thread starter flouger
  • Start date Start date
F

flouger

Hi when I try to export a chart programmability to an image i receive
the 800A03EC error on the second try. The first try works well
though. Im not really sure what to try next any thoughts?
Here is my code listing

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

namespace DisplayEditor
{
public partial class ExcelChartSelector2 : Form
{
public string FileName;
public string ChartName;
Excel.Application ExcelObj;
Excel.Workbook workBook ;
protected override void OnClosing(CancelEventArgs e)
{
workBook.Close(false, System.Reflection.Missing.Value,
System.Reflection.Missing.Value);
base.OnClosing(e);
}
public ExcelChartSelector2()
{
InitializeComponent();
}

private void ExcelChartSelector2_Load(object sender, EventArgs
e)
{
ExcelObj = new Excel.Application();
//System.Globalization.CultureInfo enUS = new
System.Globalization.CultureInfo("en-US");
//System.Threading.Thread.CurrentThread.CurrentCulture =
enUS;
object missing = System.Reflection.Missing.Value;
workBook = ExcelObj.Workbooks.Open(FileName, missing,
missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing);
//Excel.Chart chart = workBook.Sheets;
foreach(Excel.Chart chart in workBook.Charts ){
listBox1.Items.Add(chart.Name);
}

//workBook.Close(false, System.Reflection.Missing.Value,
System.Reflection.Missing.Value);

//Excel.Chart chart =
((Excel.Worksheet)sheets[chartName]).ChartObjects(0);
//chart.Export(@".\temp\1.gif", "GIF", false);//save it
//load it to be displayed
//Image i = new Bitmap(@".\temp\1.gif");
}

private void listBox1_SelectedIndexChanged(object sender,
EventArgs e)
{

//workBook = ExcelObj.Workbooks.Open(FileName, false,
true, 5, "", "", true, Excel.XlPlatform.xlWindows, "", false, false,
0,false );
Excel.Chart chart = (Excel.Chart)
workBook.Charts[listBox1.SelectedItem];
ChartName = chart.Name;
try { System.IO.File.Delete(@".\temp\1.gif"); }
catch (Exception ee) { }

try
{

System.Threading.Thread.CurrentThread.CurrentCulture=
new System.Globalization.CultureInfo("en-US");
chart.Export(@".\temp\1.gif", "gif", false);//save it



}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}


//load it to be displayed
Image i = new Bitmap(@".\temp\1.gif");
pictureBox1.Image = i;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top