本文整理汇总了C#中DocumentBuilder.InsertNode方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder.InsertNode方法的具体用法?C# DocumentBuilder.InsertNode怎么用?C# DocumentBuilder.InsertNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentBuilder
的用法示例。
在下文中一共展示了DocumentBuilder.InsertNode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Create an empty document and DocumentBuilder object.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a Comment.
Comment comment = new Comment(doc);
// Insert some text into the comment.
Paragraph commentParagraph = new Paragraph(doc);
commentParagraph.AppendChild(new Run(doc, "This is comment!!!"));
comment.AppendChild(commentParagraph);
// Create CommentRangeStart and CommentRangeEnd.
int commentId = 0;
CommentRangeStart start = new CommentRangeStart(doc, commentId);
CommentRangeEnd end = new CommentRangeEnd(doc, commentId);
// Insert some text into the document.
builder.Write("This is text before comment ");
// Insert comment and comment range start.
builder.InsertNode(comment);
builder.InsertNode(start);
// Insert some more text.
builder.Write("This is commented text ");
// Insert end of comment range.
builder.InsertNode(end);
// And finaly insert some more text.
builder.Write("This is text aftr comment");
// Save output document.
doc.Save("Insert a Comment in Word Processing document.docx");
}
示例2: AddImageToPage
/// <summary>
/// Adds an image to a page using the supplied paragraph.
/// </summary>
/// <param name="para">The paragraph to an an image to.</param>
/// <param name="page">The page number the paragraph appears on.</param>
public static void AddImageToPage(Paragraph para, int page)
{
Document doc = (Document)para.Document;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveTo(para);
// Add a logo to the top left of the page. The image is placed infront of all other text.
Shape shape = builder.InsertImage(gDataDir + "Aspose Logo.png", RelativeHorizontalPosition.Page, 60,
RelativeVerticalPosition.Page, 60, -1, -1, WrapType.None);
// Add a textbox next to the image which contains some text consisting of the page number.
Shape textBox = new Shape(doc, ShapeType.TextBox);
// We want a floating shape relative to the page.
textBox.WrapType = WrapType.None;
textBox.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
textBox.RelativeVerticalPosition = RelativeVerticalPosition.Page;
// Set the textbox position.
textBox.Height = 30;
textBox.Width = 200;
textBox.Left = 150;
textBox.Top = 80;
// Add the textbox and set text.
textBox.AppendChild(new Paragraph(doc));
builder.InsertNode(textBox);
builder.MoveTo(textBox.FirstChild);
builder.Writeln("This is a custom note for page " + page);
}
示例3: MailMerge_MergeField
private void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
{
#region 處理照片
if (e.FieldName == "照片")
{
DocumentBuilder builder1 = new DocumentBuilder(e.Document);
builder1.MoveToField(e.Field, true);
byte[] photoBytes = null;
try
{
photoBytes = Convert.FromBase64String("" + e.FieldValue);
}
catch (Exception ex)
{
//builder1.Write("照片粘貼處");
e.Field.Remove();
return;
}
if (photoBytes == null || photoBytes.Length == 0)
{
//builder1.Write("照片粘貼處");
e.Field.Remove();
return;
}
e.Field.Remove();
Shape photoShape = new Shape(e.Document, ShapeType.Image);
photoShape.ImageData.SetImage(photoBytes);
photoShape.WrapType = WrapType.Inline;
#region AutoResize
double origHWRate = photoShape.ImageData.ImageSize.HeightPoints / photoShape.ImageData.ImageSize.WidthPoints;
double shapeHeight = (builder1.CurrentParagraph.ParentNode.ParentNode as Row).RowFormat.Height;
double shapeWidth = (builder1.CurrentParagraph.ParentNode as Cell).CellFormat.Width;
if ((shapeHeight / shapeWidth) < origHWRate)
shapeWidth = shapeHeight / origHWRate;
else
shapeHeight = shapeWidth * origHWRate;
#endregion
photoShape.Height = shapeHeight * 0.9;
photoShape.Width = shapeWidth * 0.9;
builder1.InsertNode(photoShape);
}
#endregion
}
示例4: Run
public static void Run()
{
// ExStart:CheckBoxTypeContentControl
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
// Open the empty document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
StructuredDocumentTag SdtCheckBox = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
// Insert content control into the document
builder.InsertNode(SdtCheckBox);
dataDir = dataDir + "CheckBoxTypeContentControl_out.docx";
doc.Save(dataDir, SaveFormat.Docx);
// ExEnd:CheckBoxTypeContentControl
Console.WriteLine("\nCheckBox type content control created successfully.\nFile saved at " + dataDir);
}
示例5: CheckBox
public void CheckBox()
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
StructuredDocumentTag sdtCheckBox = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
sdtCheckBox.Checked = true;
//Insert content control into the document
builder.InsertNode(sdtCheckBox);
MemoryStream dstStream = new MemoryStream();
doc.Save(dstStream, SaveFormat.Docx);
NodeCollection sdts = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
StructuredDocumentTag sdt = (StructuredDocumentTag)sdts[0];
Assert.AreEqual(true, sdt.Checked);
}
示例6: Run
public static void Run()
{
// ExStart:AddGroupShapeToDocument
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
Document doc = new Document();
doc.EnsureMinimum();
GroupShape gs = new GroupShape(doc);
Shape shape = new Shape(doc, Drawing.ShapeType.AccentBorderCallout1);
shape.Width = 100;
shape.Height = 100;
gs.AppendChild(shape);
Shape shape1 = new Shape(doc, Drawing.ShapeType.ActionButtonBeginning);
shape1.Left = 100;
shape1.Width = 100;
shape1.Height = 200;
gs.AppendChild(shape1);
gs.Width = 200;
gs.Height = 200;
gs.CoordSize = new System.Drawing.Size(200, 200);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(gs);
dataDir = dataDir + "groupshape-doc_out.doc";
// Save the document to disk.
doc.Save(dataDir);
// ExEnd:AddGroupShapeToDocument
Console.WriteLine("\nGroup shape added successfully.\nFile saved at " + dataDir);
}
示例7: MailMerge_MergeField
void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
{
if (e.FieldName == "入學照片" || e.FieldName == "入學照片2" ||e.FieldName == "畢業照片" || e.FieldName == "畢業照片2")
{
if (e.FieldValue != null && e.FieldValue.ToString()!="")
{
byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];
if (photo != null && photo.Length > 0)
{
DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
photoBuilder.MoveToField(e.Field, true);
e.Field.Remove();
Shape photoShape = new Shape(e.Document, ShapeType.Image);
photoShape.ImageData.SetImage(photo);
photoShape.WrapType = WrapType.Inline;
Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
//cell.CellFormat.LeftPadding = 0;
//cell.CellFormat.RightPadding = 0;
if (e.FieldName == "入學照片" || e.FieldName == "畢業照片")
{
// 1吋
photoShape.Width = ConvertUtil.MillimeterToPoint(25);
photoShape.Height = ConvertUtil.MillimeterToPoint(35);
}
else
{
//2吋
photoShape.Width = ConvertUtil.MillimeterToPoint(35);
photoShape.Height = ConvertUtil.MillimeterToPoint(45);
}
photoBuilder.InsertNode(photoShape);
}
}
}
}
示例8: CreateLinkedImage
public void CreateLinkedImage()
{
//ExStart
//ExFor:Shape.ImageData
//ExFor:ImageData
//ExFor:ImageData.SourceFullName
//ExFor:ImageData.SetImage(string)
//ExFor:DocumentBuilder.InsertNode
//ExSummary:Shows how to insert a linked image into a document.
DocumentBuilder builder = new DocumentBuilder();
string imageFileName = ExDir + "Hammer.wmf";
builder.Write("Image linked, not stored in the document: ");
Shape linkedOnly = new Shape(builder.Document, ShapeType.Image);
linkedOnly.WrapType = WrapType.Inline;
linkedOnly.ImageData.SourceFullName = imageFileName;
builder.InsertNode(linkedOnly);
builder.Writeln();
builder.Write("Image linked and stored in the document: ");
Shape linkedAndStored = new Shape(builder.Document, ShapeType.Image);
linkedAndStored.WrapType = WrapType.Inline;
linkedAndStored.ImageData.SourceFullName = imageFileName;
linkedAndStored.ImageData.SetImage(imageFileName);
builder.InsertNode(linkedAndStored);
builder.Writeln();
builder.Write("Image stored in the document, but not linked: ");
Shape stored = new Shape(builder.Document, ShapeType.Image);
stored.WrapType = WrapType.Inline;
stored.ImageData.SetImage(imageFileName);
builder.InsertNode(stored);
builder.Writeln();
builder.Document.Save(ExDir + "Image.CreateLinkedImage Out.doc");
//ExEnd
}
示例9: FromStrings
public static Document FromStrings(string[] strings, out Run[] runs)
{
var builder = new DocumentBuilder();
var runList = new List<Run>();
var comments = new Dictionary<string, Comment>();
foreach (var str in strings)
{
// Bookmark
if (str.StartsWith("@{") && str.EndsWith("}"))
{
if (str.StartsWith("@{/"))
{
var bookmarkName = str.Substring(3, str.Length - 4);
builder.EndBookmark(bookmarkName);
}
else
{
var bookmarkName = str.Substring(2, str.Length - 3);
builder.StartBookmark(bookmarkName);
}
continue;
}
// Comment
if (str.StartsWith("!{") && str.EndsWith("}"))
{
if (str.StartsWith("!{/"))
{
var commentName = str.Substring(3, str.Length - 4);
var comment = comments[commentName];
var commentEnd = new CommentRangeEnd(builder.Document, comment.Id);
builder.InsertNode(commentEnd);
}
else
{
var commentName = str.Substring(2, str.Length - 3);
var comment = new Comment(builder.Document, "", "", DateTime.Now);
comments.Add(commentName, comment);
comment.SetText("Comment: " + commentName);
builder.InsertNode(comment);
var commentStart = new CommentRangeStart(builder.Document, comment.Id);
builder.InsertNode(commentStart);
}
continue;
}
runList.Add(builder.InsertRun(str));
}
runs = runList.ToArray();
return builder.Document;
}
示例10: ChangeStrokeProperties
public void ChangeStrokeProperties()
{
//ExStart
//ExFor:Stroke
//ExSummary:Shows how change stroke properties
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a new shape of type Rectangle
Shape rectangle = new Shape(doc, ShapeType.Rectangle);
//Change stroke properties
Stroke stroke = rectangle.Stroke;
stroke.On = true;
stroke.Weight = 5;
stroke.Color = Color.Red;
stroke.DashStyle = DashStyle.ShortDashDotDot;
stroke.JoinStyle = JoinStyle.Miter;
stroke.EndCap = EndCap.Square;
stroke.LineStyle = ShapeLineStyle.Triple;
//Insert shape object
builder.InsertNode(rectangle);
//ExEnd
MemoryStream dstStream = new MemoryStream();
doc.Save(dstStream, SaveFormat.Docx);
rectangle = (Shape)doc.GetChild(NodeType.Shape, 0, true);
Stroke strokeAfter = rectangle.Stroke;
Assert.AreEqual(true, strokeAfter.On);
Assert.AreEqual(5, strokeAfter.Weight);
Assert.AreEqual(Color.Red.ToArgb(), strokeAfter.Color.ToArgb());
Assert.AreEqual(DashStyle.ShortDashDotDot, strokeAfter.DashStyle);
Assert.AreEqual(JoinStyle.Miter, strokeAfter.JoinStyle);
Assert.AreEqual(EndCap.Square, strokeAfter.EndCap);
Assert.AreEqual(ShapeLineStyle.Triple, strokeAfter.LineStyle);
}
示例11: Fill
public void Fill()
{
//ExStart
//ExFor:Shape.Fill
//ExFor:Shape.FillColor
//ExFor:Fill
//ExFor:Fill.Opacity
//ExSummary:Demonstrates how to create shapes with fill.
DocumentBuilder builder = new DocumentBuilder();
builder.Writeln();
builder.Writeln();
builder.Writeln();
builder.Write("Some text under the shape.");
// Create a red balloon, semitransparent.
// The shape is floating and its coordinates are (0,0) by default, relative to the current paragraph.
Shape shape = new Shape(builder.Document, ShapeType.Balloon);
shape.FillColor = Color.Red;
shape.Fill.Opacity = 0.3;
shape.Width = 100;
shape.Height = 100;
shape.Top = -100;
builder.InsertNode(shape);
builder.Document.Save(MyDir + @"\Artifacts\Shape.Fill.doc");
//ExEnd
}
示例12: MailMerge_MergeField
void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
{
if (e.FieldName == "照片" || e.FieldName == "照片2")
{
if (e.FieldValue != null)
{
byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];
if (photo != null && photo.Length > 0)
{
DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
photoBuilder.MoveToField(e.Field, true);
e.Field.Remove();
//Paragraph paragraph = photoBuilder.InsertParagraph();// new Paragraph(e.Document);
Shape photoShape = new Shape(e.Document, ShapeType.Image);
photoShape.ImageData.SetImage(photo);
photoShape.WrapType = WrapType.Inline;
//Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
//cell.CellFormat.LeftPadding = 0;
//cell.CellFormat.RightPadding = 0;
if (e.FieldName == "照片")
{
// 1吋
photoShape.Width = ConvertUtil.MillimeterToPoint(25);
photoShape.Height = ConvertUtil.MillimeterToPoint(35);
}
else
{
//2吋
photoShape.Width = ConvertUtil.MillimeterToPoint(35);
photoShape.Height = ConvertUtil.MillimeterToPoint(45);
}
//paragraph.AppendChild(photoShape);
photoBuilder.InsertNode(photoShape);
}
}
}
if (e.FieldName == "畢業照片" || e.FieldName == "畢業照片2")
{
if (e.FieldValue != null)
{
byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];
if (photo != null && photo.Length > 0)
{
DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
photoBuilder.MoveToField(e.Field, true);
e.Field.Remove();
//Paragraph paragraph = photoBuilder.InsertParagraph();// new Paragraph(e.Document);
Shape photoShape = new Shape(e.Document, ShapeType.Image);
photoShape.ImageData.SetImage(photo);
photoShape.WrapType = WrapType.Inline;
//Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
//cell.CellFormat.LeftPadding = 0;
//cell.CellFormat.RightPadding = 0;
if (e.FieldName == "畢業照片")
{
// 1吋
photoShape.Width = ConvertUtil.MillimeterToPoint(25);
photoShape.Height = ConvertUtil.MillimeterToPoint(35);
}
else
{
//2吋
photoShape.Width = ConvertUtil.MillimeterToPoint(35);
photoShape.Height = ConvertUtil.MillimeterToPoint(45);
}
//paragraph.AppendChild(photoShape);
photoBuilder.InsertNode(photoShape);
}
}
}
if (e.FieldName == "條碼")
{
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToField(e.Field, true);
e.Field.Remove();
BarCodeBuilder bb = new BarCodeBuilder();
if (e.FieldValue != null && e.FieldValue.ToString() != "")
{
bb.CodeText = e.FieldValue.ToString();
bb.SymbologyType = Symbology.Code128;
bb.CodeLocation = CodeLocation.None;
bb.xDimension = 0.5f;
bb.BarHeight = 6.0f;
MemoryStream stream = new MemoryStream();
bb.Save(stream, ImageFormat.Jpeg);
builder.InsertImage(stream);
}
}
}