EXCEL INTERLOP CHART ERROR C#-发生共享冲突. (来自HRESULT的异常:0x80030020(STG_E_SHAREVIOLATION)) [英] EXCEL INTERLOP CHART ERROR C# - A share violation has occurred. (Exception from HRESULT: 0x80030020 (STG_E_SHAREVIOLATION))

查看:292
本文介绍了EXCEL INTERLOP CHART ERROR C#-发生共享冲突. (来自HRESULT的异常:0x80030020(STG_E_SHAREVIOLATION))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void button1_Click(object sender, EventArgs e)
        {
            

            xlApp = new Excel.ApplicationClass();
            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            //add data 
            xlWorkSheet.Cells[1, 1] = "";
            xlWorkSheet.Cells[1, 2] = "Student1";
            xlWorkSheet.Cells[1, 3] = "Student2";
            xlWorkSheet.Cells[1, 4] = "Student3";

            xlWorkSheet.Cells[2, 1] = "Term1";
            xlWorkSheet.Cells[2, 2] = textBox1.Text ;
            xlWorkSheet.Cells[2, 3] = "65";
            xlWorkSheet.Cells[2, 4] = "45";

            xlWorkSheet.Cells[3, 1] = "Term2";
            xlWorkSheet.Cells[3, 2] = "78";
            xlWorkSheet.Cells[3, 3] = "72";
            xlWorkSheet.Cells[3, 4] = "60";

            xlWorkSheet.Cells[4, 1] = "Term3";
            xlWorkSheet.Cells[4, 2] = "82";
            xlWorkSheet.Cells[4, 3] = "80";
            xlWorkSheet.Cells[4, 4] = "65";

            xlWorkSheet.Cells[5, 1] = "Term4";
            xlWorkSheet.Cells[5, 2] = "75";
            xlWorkSheet.Cells[5, 3] = "82";
            xlWorkSheet.Cells[5, 4] = "68";

            Excel.Range chartRange ; 
            
            Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
            Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 300, 250);
            
            Excel.Chart chartPage = myChart.Chart;

            chartRange = xlWorkSheet.get_Range("A1", "d5");
            chartPage.SetSourceData(chartRange, misValue);
            chartPage.ChartType = Excel.XlChartType.xlColumnClustered;
            chartPage.Export(@"D:\excel_chart_export.bmp", "BMP", misValue);
            pictureBox1.Image = new Bitmap(@"D:\excel_chart_export.bmp");
           xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
        xlWorkBook.Close(true, misValue, misValue);
          xlApp.Quit();

          releaseObject(xlWorkSheet);
           releaseObject(xlWorkBook);
           releaseObject(xlApp);

          MessageBox.Show("Excel file created , you can find the file c:\\csharp.net-informations.xls");
            
        }

        private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }




当我按两次Button1时出现错误
发生了违反股份的情况. (来自HRESULT的异常:0x80030020(STG_E_SHAREVIOLATION))

请帮我解决这个问题.我想更改文本框中的值并相应地生成图表.


我复制到剪贴板的异常
未处理System.Runtime.InteropServices.COMException
Message =发生共享冲突.(来自HRESULT的异常:0x80030020(STG_E_SHAREVIOLATION))"
Source ="Microsoft.Office.Interop.Excel"
ErrorCode = -2147287008
StackTrace:
在Microsoft.Office.Interop.Excel._Chart.Export(字符串文件名,对象FilterName,对象交互式)
在C:\ Users \ Ankit \ Documents \ Visual Studio 2008 \ Projects \ ExcelChartTest \ ExcelChartTest \ Form1.cs:line 65中的ExcelChartTest.Form1.button1_Click(Object sender,EventArgs e)中 在System.Windows.Forms.Control.OnClick(EventArgs e)
在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)中
在System.Windows.Forms.Control.WmMouseUp上(消息和m,MouseButtons按钮,Int32单击)
在System.Windows.Forms.Control.WndProc(Message& m)中
在System.Windows.Forms.ButtonBase.WndProc(Message& m)中
在System.Windows.Forms.Button.WndProc(Message& m)中
在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)中
在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms中. UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32原因,Int32 pvLoopData)
在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32原因,ApplicationContext上下文)中
在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32原因,ApplicationContext上下文)
在C:\ Users \ Ankit \ Documents \ Visual Studio 2008 \ Projects \ ExcelChartTest \ ExcelChartTest \ Program.cs:第17行的ExcelChartTest.Program.Main()中 在System.AppDomain._nExecuteAssembly(程序集程序集,String [] args)中
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态)处
在System.Threading.ThreadHelper.ThreadStart()处
InnerException:



将OP的答案移至此处
没有像Interlop.Microsoft.office.Core.dll这样的东西
但是Interop.Microsoft.Office.Interop.Excel.dll的版本为12




When I press Button1 twice I get the error
A share violation has occurred. (Exception from HRESULT: 0x80030020 (STG_E_SHAREVIOLATION))

Please help me solve this issue. I want to change the value in the textbox and generate charts accordingly.


The Exception which I copied to clipboard
System.Runtime.InteropServices.COMException was unhandled
Message="A share violation has occurred. (Exception from HRESULT: 0x80030020 (STG_E_SHAREVIOLATION))"
Source="Microsoft.Office.Interop.Excel"
ErrorCode=-2147287008
StackTrace:
at Microsoft.Office.Interop.Excel._Chart.Export(String Filename, Object FilterName, Object Interactive)
at ExcelChartTest.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Ankit\Documents\Visual Studio 2008\Projects\ExcelChartTest\ExcelChartTest\Form1.cs:line 65
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms. UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at ExcelChartTest.Program.Main() in C:\Users\Ankit\Documents\Visual Studio 2008\Projects\ExcelChartTest\ExcelChartTest\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:



Moved OP''s answer here
There is nothing like Interlop.Microsoft.office.Core.dll
but the version of Interop.Microsoft.Office.Interop.Excel.dll is 12

推荐答案

请交叉检查
的版本
Please cross check the version of the

Interop.Microsoft.Office.Interop.Excel.dll
Interop.Microsoft.Office.Core.dll



请参考这两个dll.



these two dll s with your refence.


int flag=0;
if(flag==0)
{
chartPage.Export(@"D:\excel_chart_export.bmp", "BMP", misValue);
            pictureBox1.Image = new Bitmap(@"D:\excel_chart_export.bmp");
flag=1;
}
else
{
chartPage.Export(@"D:\excel_chart_export2.bmp", "BMP", misValue);
            pictureBox1.Image = new Bitmap(@"D:\excel_chart_export2.bmp");
flag=0;
}


在这里,使bmp文件保持打开状态的文件一次只能保存一个文件. :)


Here the file which keeps the bmp file open can hold only one file at a time. :)


这篇关于EXCEL INTERLOP CHART ERROR C#-发生共享冲突. (来自HRESULT的异常:0x80030020(STG_E_SHAREVIOLATION))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆