Charts from Excel 2002 to Word 2002 with C#

S

stocki

Hi Everybody,

one of my C# apps copies charts from an Excel workbook into a table in
a word document.

((Excel.ChartObject) myGraphicsWorksheet.ChartObjects(1)).Copy();
myvalue = Word.WdPasteDataType.wdPasteMetafilePicture;
myOutRange.PasteSpecial( ref mymissingValue, ref mymissingValue, ref
mymissingValue, ref mymissingValue, ref myvalue, ref mymissingValue,
ref mymissingValue );


Afterwards I am going to position the graph within the respective table
cell:

object shapeCount = m_wordDoc.Shapes.Count;
myShape = m_wordDoc.Shapes.Item( ref shapeCount );
myShape.Left = graphPos

For the most of the documents this works perfect. If the document is
bigger the application stumbels when trying to set the left property of
the shape. I ran the whole lot in the development environment setting a
breakpoint onto the line with the left property. When the breakpoint
was reached I waited a little while. When pressing the F10 key to go
ahead, everything worked fine. When I toggled the breakpoint the
problem occured again.

My impression is that Word still is doing some work, when the app tries
to set the left property. The error message is something like "Can't
set the left property because the paint command does not exist for the
current selection" (or something like that)

Has anyone an idea to get around this problem? Tried it with DoEvents
and ThreadSleep without any luck ...

Cheers

Stocki
 
A

Alvin Bruney [MVP]

what is cpu and ram doing at these points? this sort of problem seems to be
very specific to your machine so i would suspect its running dry on
resources.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
 
S

stocki

Hi Alvin,

my appologies not to get back to you any sooner!!!

Thanks for your reply! Made some examinations on that issue and it
seems, that the hardware is not an issue. Although a Pentium III
machine with 512 MB Ram turns to run under 100% CPU usage and approx
250 MB of Ram, you can find the same behaviour on a AMD Athlon 64 3200
with 1GB Ram. Latter the CPU peaks up to 100% but is mostly at 50 to 60
%. RAM is about the same as on the Pentium.

Kind Regards

Andreas

what is cpu and ram doing at these points? this sort of problem seems to be
very specific to your machine so i would suspect its running dry on
resources.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


stocki said:
Hi Everybody,

one of my C# apps copies charts from an Excel workbook into a table in
a word document.

((Excel.ChartObject) myGraphicsWorksheet.ChartObjects(1)).Copy();
myvalue = Word.WdPasteDataType.wdPasteMetafilePicture;
myOutRange.PasteSpecial( ref mymissingValue, ref mymissingValue, ref
mymissingValue, ref mymissingValue, ref myvalue, ref mymissingValue,
ref mymissingValue );


Afterwards I am going to position the graph within the respective table
cell:

object shapeCount = m_wordDoc.Shapes.Count;
myShape = m_wordDoc.Shapes.Item( ref shapeCount );
myShape.Left = graphPos

For the most of the documents this works perfect. If the document is
bigger the application stumbels when trying to set the left property of
the shape. I ran the whole lot in the development environment setting a
breakpoint onto the line with the left property. When the breakpoint
was reached I waited a little while. When pressing the F10 key to go
ahead, everything worked fine. When I toggled the breakpoint the
problem occured again.

My impression is that Word still is doing some work, when the app tries
to set the left property. The error message is something like "Can't
set the left property because the paint command does not exist for the
current selection" (or something like that)

Has anyone an idea to get around this problem? Tried it with DoEvents
and ThreadSleep without any luck ...

Cheers

Stocki
 
A

Alvin Bruney [MVP]

post a short but complete program demonstrating the problem and we will take
a look. Check this link BEFORE you post.
http://www.yoda.arachsys.com/csharp/complete.html

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


stocki said:
Hi Alvin,

my appologies not to get back to you any sooner!!!

Thanks for your reply! Made some examinations on that issue and it
seems, that the hardware is not an issue. Although a Pentium III
machine with 512 MB Ram turns to run under 100% CPU usage and approx
250 MB of Ram, you can find the same behaviour on a AMD Athlon 64 3200
with 1GB Ram. Latter the CPU peaks up to 100% but is mostly at 50 to 60
%. RAM is about the same as on the Pentium.

Kind Regards

Andreas

what is cpu and ram doing at these points? this sort of problem seems to
be
very specific to your machine so i would suspect its running dry on
resources.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


stocki said:
Hi Everybody,

one of my C# apps copies charts from an Excel workbook into a table in
a word document.

((Excel.ChartObject) myGraphicsWorksheet.ChartObjects(1)).Copy();
myvalue = Word.WdPasteDataType.wdPasteMetafilePicture;
myOutRange.PasteSpecial( ref mymissingValue, ref mymissingValue, ref
mymissingValue, ref mymissingValue, ref myvalue, ref mymissingValue,
ref mymissingValue );


Afterwards I am going to position the graph within the respective table
cell:

object shapeCount = m_wordDoc.Shapes.Count;
myShape = m_wordDoc.Shapes.Item( ref shapeCount );
myShape.Left = graphPos

For the most of the documents this works perfect. If the document is
bigger the application stumbels when trying to set the left property of
the shape. I ran the whole lot in the development environment setting a
breakpoint onto the line with the left property. When the breakpoint
was reached I waited a little while. When pressing the F10 key to go
ahead, everything worked fine. When I toggled the breakpoint the
problem occured again.

My impression is that Word still is doing some work, when the app tries
to set the left property. The error message is something like "Can't
set the left property because the paint command does not exist for the
current selection" (or something like that)

Has anyone an idea to get around this problem? Tried it with DoEvents
and ThreadSleep without any luck ...

Cheers

Stocki
 
S

stocki

Hi Alvin,

thanks for this special offer! The problem is though that you will need
the Excel workbook with the graphics and all the word docs this
document need. As they contain confidential information I am not in a
position to send them over to you.

Meanwhile I have found some workaround which works for me at the
moment:

try
{
myShape.Left = graphPos;
}
catch (Exception ex)
{
Console.WriteLine( ex.Message ) ;
Console.WriteLine( "In Try-Catch Left" ) ;
for ( int i = 0; i <= 100; i++ )
{
System.Windows.Forms.Application.DoEvents () ;
System.Threading.Thread.Sleep( 100 ) ;
}
myShape.Left = graphPos;
}

Thanks for you support and have a nice weekend!

Regards

Andreas

post a short but complete program demonstrating the problem and we will take
a look. Check this link BEFORE you post.
http://www.yoda.arachsys.com/csharp/complete.html

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


stocki said:
Hi Alvin,

my appologies not to get back to you any sooner!!!

Thanks for your reply! Made some examinations on that issue and it
seems, that the hardware is not an issue. Although a Pentium III
machine with 512 MB Ram turns to run under 100% CPU usage and approx
250 MB of Ram, you can find the same behaviour on a AMD Athlon 64 3200
with 1GB Ram. Latter the CPU peaks up to 100% but is mostly at 50 to 60
%. RAM is about the same as on the Pentium.

Kind Regards

Andreas

what is cpu and ram doing at these points? this sort of problem seems to
be
very specific to your machine so i would suspect its running dry on
resources.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


Hi Everybody,

one of my C# apps copies charts from an Excel workbook into a table in
a word document.

((Excel.ChartObject) myGraphicsWorksheet.ChartObjects(1)).Copy();
myvalue = Word.WdPasteDataType.wdPasteMetafilePicture;
myOutRange.PasteSpecial( ref mymissingValue, ref mymissingValue, ref
mymissingValue, ref mymissingValue, ref myvalue, ref mymissingValue,
ref mymissingValue );


Afterwards I am going to position the graph within the respective table
cell:

object shapeCount = m_wordDoc.Shapes.Count;
myShape = m_wordDoc.Shapes.Item( ref shapeCount );
myShape.Left = graphPos

For the most of the documents this works perfect. If the document is
bigger the application stumbels when trying to set the left property of
the shape. I ran the whole lot in the development environment setting a
breakpoint onto the line with the left property. When the breakpoint
was reached I waited a little while. When pressing the F10 key to go
ahead, everything worked fine. When I toggled the breakpoint the
problem occured again.

My impression is that Word still is doing some work, when the app tries
to set the left property. The error message is something like "Can't
set the left property because the paint command does not exist for the
current selection" (or something like that)

Has anyone an idea to get around this problem? Tried it with DoEvents
and ThreadSleep without any luck ...

Cheers

Stocki
 

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

Top