Crystal Report og OLE object

Tags:    c#

Hejsa...

Jeg rodet med en C# win-form...hvor jeg har oprettet en Crystal Report(og en CrystalReportViewer). Jeg vil gerne indsætte et OLE object heri (et pdf, word eller lign. doc )....Men jeg kan ikke få det til at virke!? Hver gang jeg indsætte det, viser den det enten ikke i GUI'en når jeg har kompileret, siger at linket til filen er "broken" - trods jeg lige har lavet det....og nogle gang skriver den, at jeg skal sikre mig, at programmet findes i "system registry"....?

Hvad skal jeg gøre? Jeg håber VIRKELIG i kan hjælpe mig - fordi jeg har brugt så lang tid på dette - men uden held...

mvh Martin



6 svar postet i denne tråd vises herunder
2 indlæg har modtaget i alt 8 karma
Sorter efter stemmer Sorter efter dato
Hejsa...

Jeg rodet med en C# win-form...hvor jeg har oprettet en Crystal Report(og en CrystalReportViewer). Jeg vil gerne indsætte et OLE object heri (et pdf, word eller lign. doc )....Men jeg kan ikke få det til at virke!? Hver gang jeg indsætte det, viser den det enten ikke i GUI'en når jeg har kompileret, siger at linket til filen er "broken" - trods jeg lige har lavet det....og nogle gang skriver den, at jeg skal sikre mig, at programmet findes i "system registry"....?

Hvad skal jeg gøre? Jeg håber VIRKELIG i kan hjælpe mig - fordi jeg har brugt så lang tid på dette - men uden held...

mvh Martin


Pablo hvis der du ikke får svar her (Hvad jeg ikke tror du gør) så gå ind på http://www.eksperten.dk!! Den sidder der ihvertfald nogen som kan hjælpe dig!! Det er jeg sikker på!!
MxS @ http://mxs.frac.dk
Slamkodning for fred



Ifølge MSDN er dette måden at gøre det på :

This walkthrough demonstrates the basics of using buttons and text boxes on Microsoft Office Word 2003 documents. To see the result as a completed sample, see Word Document with Controls Sample.

The walkthrough contains several steps:

*Creating a New Project
*Adding Controls to the Word Document
*Adding a Reference to the Controls Component
*Adding Namespace Statements and Declaring Class-Level Variables
*Initializing the Controls
*Populating the Text Box when the Button Is Clicked
*Testing
*Prerequisites
*To complete this walkthrough, you will need:

Microsoft Visual Studio Tools for the Microsoft Office System.
Microsoft Office Word 2003.

*Creating a New Project
In this step, you will create a Word document project.

To create a new project

From the File menu, point to New, and then click Project to display the New Project dialog box.
In the Project Types pane, expand Microsoft Office System Projects, and then select Visual Basic Projects or Visual C# Projects.
In the Templates pane, select Word Document.
Name the project My Word Button, then click OK.
The Microsoft Office Project Wizard appears.

Make sure that Create New Office Document is selected, note the name and location so you can open the document for editing, and then click Finish.
Visual Studio .NET creates a new Word document at the specified location and adds the My Word Button project to Solution Explorer.

Adding Controls to the Word Document
For this walkthrough, you will need a command button and a text box on the Word document.

To add a command button and a text box

Open the My Word Button.doc document in Microsoft Word.
A warning might appear stating that the assembly name or Assembly Link Location property is corrupted, because you have not compiled the assembly yet. Click OK to close the warning.

On the View menu, point to Toolbars and then click Control Toolbox.
Click the Text Box control on the Control Toolbox.
A text box appears at the insertion point in the document.

Right-click the text box and then click Properties in the shortcut menu.
Change the (Name) property of the text box to textboxShowText.
Click the Command Button on the Control Toolbox.
A button appears beside the text box.

Change the (Name) property of the button to buttonShowText.
Close the Properties window and the Control Toolbox.
Save and close the document.
Now return to the project in Visual Studio .NET to add a reference and work in the code file behind the worksheet.

Adding a Reference to the Controls Component
To use controls on a document, you must have a reference to MSForms in your project.

To add a reference to MSForms

Select References in the Solution Explorer window in Visual Studio .NET.
Open the Project menu and then click Add Reference.
The Add Reference dialog box appears.

Click the COM tab.
Select Microsoft Forms 2.0 Object Library in the Component Name list and then click Select.
Note There might be two components with this name, in which case use the first one in the list.
Click OK to add the reference to your project.
Now add namespace references to your code.

Adding Namespace Statements and Declaring Class-Level Variables
Add the necessary namespace statements and class-level variables to your code file.

To add statements and class-level variable

Open the ThisDocument.vb or ThisDocument.cs file in Visual Studio .NET.
Add these statements to the top of the code file:
' Visual Basic
Imports System.Runtime.InteropServices
Imports MSForms = Microsoft.Vbe.Interop.Forms

// C#
using System.Runtime.InteropServices;
using MSForms = Microsoft.Vbe.Interop.Forms;
Add the following variable declaration to the OfficeCodeBehind class, just above the Generated initialization code region, so that the variable is scoped for the class:
' Visual Basic
Private WithEvents buttonShowText As MSForms.CommandButton
Private WithEvents textboxShowText As MSForms.TextBox

// C#
private MSForms.CommandButton buttonShowText = null;
private MSForms.TextBox textboxShowText = null;
Next, initialize the controls when the worksheet is opened and write text to the text box when the button is clicked.

Initializing the Controls
Before you can use the controls on a worksheet, they must be initialized.

To initialize the controls

Find the ThisDocument_Open method in the class and add the following code to find and initialize the controls. The FindControl function that is called in this method is included in the project template.
' Visual Basic
Private Sub ThisDocument_Open() Handles ThisDocument.Open
Dim control As Object
control = Me.FindControl("buttonShowText")
Me.buttonShowText = CType(control, MSForms.CommandButton)

control = Me.FindControl("textboxShowText")
Me.textboxShowText = CType(control, MSForms.TextBox)
End Sub

// C#
public void ThisDocument_Open()
{
object control;

control = this.FindControl("buttonShowText");
this.buttonShowText = control as MSForms.CommandButton;

control = this.FindControl("textboxShowText");
this.textboxShowText = control as MSForms.TextBox;

// Attaches the events after making sure the variables
// have been properly initiliazed.
if (this.buttonShowText != null && this.textboxShowText != null)
{
this.buttonShowText.Click += new
MSForms.CommandButtonEvents_ClickEventHandler
(buttonShowText_Click);
}
}
Now write the code to run when the button is clicked.

Populating the Text Box when the Button Is Clicked
When the user clicks the button, Hello World! appears in the text box.

To write to the text box when the button is clicked

Add a method to handle the buttonShowText object's Click event.
Write "Hello World! " to the text box when the button is clicked.
' Visual Basic
Private Sub buttonShowText_Click() Handles buttonShowText.Click
Me.textboxShowText.Text += "Hello World! "
End Sub

// C#
private void buttonShowText_Click()
{
this.textboxShowText.Text += "Hello, World! ";
}
Testing
You can now test your document to make sure that the message Hello World! appears in the text box when you click the button.

To test your document

Press F5 to run your project.
Click the button.
Confirm that Hello World! appears in the text box.
Next Steps
This walkthrough shows the basics of using buttons and text boxes on Word 2003 documents. Here are some tasks that might come next:

Do a test deployment of the project. For more information, see How to: Deploy Office Documents and Assemblies.
Use a combo box to change formatting. For more information, see Walkthrough: Changing Document Formatting Using a Combo Box.
Change WordArt formatting programmatically. For more information, see Walkthrough: Changing WordArt Formatting Using a Button on a Document .
Update a chart in a document. For more information, see Walkthrough: Updating a Chart in a Document Using Option Buttons.


(¯`·._.·[Brian Hvarregaard]·._.·´¯)



Hehe....ja helt sikkert....det var det første sted jeg oprettede dette spørgsmål...men det ser ikke ud til der findes nogle eksperter på dette område????



Er du sikker på at det er det rigtige COM objekt du har fat i fra word, det vil sige hvis du laver en blank løsning kan du så vise en word editor eller noget der ligner word.... inden du bombarderer mig med spørgsmål, vil jeg lige skynde mig at sige at jeg ikke er 100 meter mester i dette har kun brugt Internet Explorer på denne måde...

(¯`·._.·[Brian Hvarregaard]·._.·´¯)



Jeg forstår ikke helt hvad du mener...når du spørger om det er det rigtige COM objekt...? Pga...jeg trykker blot "browse" --> finder den fil (fx et word doc) jeg ønkser at indsætte og så indsætter jeg dette...Det virker "halvt" pga. jeg kan det den første side(af de fx. 50sider), men ikke resten af dokumentet...:(
og hvis jeg hiver i rammen som omringer selve objektet/doc'et...jeg så laver den blot skrift størrelse større...very wird...??

please help me!!!!

Hvis du har lyst må du meget gerne prøve at fange mig på messenger ;) hvis du altså mener at du kan hjælpe mig?-)
(mail: garfield@post5.tele.dk)


Så poster vi bare svaret herinde bagefter..hvis vi skulle være så heldige at finde en løsning ;)

/PabloPablo



Hejsa...
Pablo hvis der du ikke får svar her (Hvad jeg ikke tror du gør) så gå ind på http://www.eksperten.dk!! Den sidder der ihvertfald nogen som kan hjælpe dig!! Det er jeg sikker på!!
MxS @ http://mxs.frac.dk
Slamkodning for fred


eksperten.dk ? benyt i stedet www.asp.net under forum, der sidder nogle der ved hvad de fabler om :)

det eneste minus er at hver post skal valideres før det bliver postet.. tager oftest en time


Med venlig hilsen
/Jokke Jensen
www.jj-multimediedesign.dk



t