473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Charts from Excel 2002 to Word 2002 with C#

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

Jul 7 '06 #1
4 1983
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" <go***********@arcor.dewrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
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

Jul 7 '06 #2
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
Alvin Bruney [MVP] schrieb:
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" <go***********@arcor.dewrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
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
Jul 11 '06 #3
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" <go***********@arcor.dewrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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
Alvin Bruney [MVP] schrieb:
>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" <go***********@arcor.dewrote in message
news:11*********************@p79g2000cwp.googlegr oups.com...
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

Jul 13 '06 #4
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
Alvin Bruney [MVP] schrieb:
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" <go***********@arcor.dewrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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
Alvin Bruney [MVP] schrieb:
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" <go***********@arcor.dewrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
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
Jul 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
5
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
0
by: mscir | last post by:
Date: Thu, 08 Jul 2004 17:02:27 -0700 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <10ero4l3kp2qa65@corp.supernews.com> Reply-To: mscir@usa.com User-Agent: Mozilla/5.0...
4
by: Lewis Edward Moten III | last post by:
I have a file that users can download through a web page protected by forms authentication: Download.aspx?ID=45 and within that file ... FileInfo fileToDownload = new FileInfo(fileName);
0
by: Arjen | last post by:
Hello, I use MSDE 2000 inside my asp.net webapplication and I want to make some charts. The charts only need to be static and it will be nice if it is posible to export (Excel, spss, pdf, word)...
0
by: Rach | last post by:
Hi, Does anyone know how to export charts/graphs from EXCEl into Powerpoint-Microsoft Charts though VBA code. I would like to import the underlying data with the chart as well. I know we can...
5
by: Takeadoe | last post by:
I'm doubtful that the group is unbiased, but I will ask anyhow :o). If one intends to plot lots of data, primarily XY line and scatter plots, and mass produce them (in many cases I will be doing...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
3
by: saragoesnuts | last post by:
I have a program that automates to Excel with information in tables. I want to add charts to the excel file (pie charts, bar charts, etc). Is this possible?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.