Free Support Forum - aspose.com

Words for .NET

Received : 2007/11/14 04:43:36
Message : Trying out your product. Think it's great so far, but having trouble duplicating our existing documents. Saw on forum Frames are not supported and should be replaced by floating TextBoxes. HOW?!?!? Can't find any examples or documentation anywhere!! Please help ASAP!

I'm using Visual Basic under Visual Studio 2005 SP1, and Office 2003 on a Windows XP machine.

Thanks


This message was posted using Aspose.Live 2 Forum

Hi

Thank you for interest in Aspose products. Could you please attach your document here? (Only you and Aspose staff can download it). I will investigate this and provide you more information.

Best regards.

Thanks for fast reply. Don't think attaching document is necessary. I just need a few lines of example code to show how to use a textbox (preferably in vb.net!, but C# is ok).

I've found the textbox property under shapes in the drawing namespace, and I've added the reference to my project, and I can insert an image file using a shape. I just can't see how to use the TextBox property of the shape! Maybe I'm just thick!

I'll keep trying and I'll watch this thread in the hope of some example code! :)

Thanks

Here is code example.

C#

Document doc = new Document();

Shape shape = new Shape(doc, ShapeType.TextBox);

doc.Sections[0].Body.FirstParagraph.AppendChild(shape);

Paragraph paragraph = new Paragraph(doc);

Run run = new Run(doc);

run.Text = "Some text in TextBox";

paragraph.AppendChild(run);

shape.AppendChild(paragraph);

doc.Save(@"321_100746_edvzim\out.doc");

VB

Dim doc As Document = New Document()

Dim shape1 As Shape = New Shape(doc, ShapeType.TextBox)

doc.Sections(0).Body.FirstParagraph.AppendChild(shape1)

Dim par As Paragraph = New Paragraph(doc)

Dim run1 As Run = New Run(doc)

run1.Text = "Some text in TextBox"

par.AppendChild(run1)

shape1.AppendChild(par)

doc.Save("out.doc")

I hope that this will help you.

Best regards.

That's exactly what I needed. Thank you - your code works perfectly! I'm planning to recommend to my director that we buy your product soon.

Hi. I'm back again!

Re: the earlier query, I'm trying to reproduce a floating address box in the top right of my document. It has to have some lines in bold type and some not bold.

The shape/textbox/run works (sort of!). I have it positioned and have hidden the border line, and I can have different font formats for each line if I use several "runs", but the text is continuous instead of having seperate lines (eg. the box contains:-

"Building NumberRoad NameDistrictTownCountyPoscode") instead of being on seperate lines. I've tried using vbNewLine, vbCrLf, etc. and tried using a run for each line, but they always end up concatenated!!!

Hope you can help. Thanks.

Hi

I think that you can try to use paragraphs. See the following code.

Dim doc As Document = New Document("in.doc")

Dim shape1 As Shape = New Shape(doc, ShapeType.TextBox)

shape1.Width = 200

shape1.Height = 50

doc.Sections(0).Body.FirstParagraph.AppendChild(shape1)

Dim par1 As Paragraph = New Paragraph(doc)

Dim run1 As Run = New Run(doc)

run1.Text = "Name: "

run1.Font.Bold = True

Dim run11 As Run = New Run(doc)

run11.Text = "Alexey Noskov"

par1.AppendChild(run1)

par1.AppendChild(run11)

Dim par2 As Paragraph = New Paragraph(doc)

Dim run2 As Run = New Run(doc)

run2.Text = "City: "

run2.Font.Bold = True

Dim run21 As Run = New Run(doc)

run21.Text = "Auckland"

par2.AppendChild(run2)

par2.AppendChild(run21)

shape1.AppendChild(par1)

shape1.AppendChild(par2)

doc.Save("out.doc")

I hope that this will help you to solve your problem.

Best regards.

That did get it working - thanks. But now I have LOTS of code just for a simple little address box!!

Maybe a 'NewLine' character for Runs, or a 'Multiline' option could be added in future releases?

Thanks for the fast help anyway.

Good Morning guys,

First, I thought you might be interested in this. I found a way to split a run, as I was asking about yesterday. Use chr(11) - It works great, so now I only need 4 runs/paragraphs instead of 11!!!

I am having a new problem now I'm afraid! I'd like to put a form-field in a text box if that's possible. I've tried various ways, and tried using paragraphs instead of a text box but I can't position the paragraph properly when there's another paragraph at the same horizontal level.

I've included an example document to give an idea of what I'm trying to replicate. The part I'm currently having trouble with is the box with 'Our ref:' and 'Your ref:' in it.

Hope you can help. Thanks again.

Hi

I think that you should use Documentbuilder class to insert FormField into the document. For example see the following code.

Dim doc As Document = New Document()

Dim builder As DocumentBuilder = New DocumentBuilder(doc)

Dim shape1 As Shape = New Shape(doc, ShapeType.TextBox)

shape1.Width = 200

shape1.Height = 50

doc.Sections(0).Body.FirstParagraph.AppendChild(shape1)

Dim par1 As Paragraph = New Paragraph(doc)

Dim run1 As Run = New Run(doc)

run1.Text = ""

par1.AppendChild(run1)

shape1.AppendChild(par1)

builder.MoveTo(run1)

'Insert Text input

builder.InsertTextInput("Input1", TextFormFieldType.RegularText, "", "test", 1024)

builder.InsertBreak(BreakType.LineBreak)

'InsertCheckBox

builder.InsertCheckBox("Check1", False, 10)

builder.InsertBreak(BreakType.LineBreak)

'Insert Combobox

builder.InsertComboBox("Combo1", New String() {"test1", "test2"}, 0)

doc.Save("out.doc")

I hope that this will help you.

Best regards.

Thanks Alexey

Again, your example has got me back on track. My document is starting to look good now!

(I see the 'InsertBreak' command does the same as my chr(11) idea so I'm using that now as it's neater.)

Thanks again!