本文整理汇总了C#中WordprocessingDocument类的典型用法代码示例。如果您正苦于以下问题:C# WordprocessingDocument类的具体用法?C# WordprocessingDocument怎么用?C# WordprocessingDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WordprocessingDocument类属于命名空间,在下文中一共展示了WordprocessingDocument类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateParts
// Adds child parts and generates content of the specified part.
private void CreateParts(WordprocessingDocument document)
{
ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);
MainDocumentPart mainDocumentPart1 = document.AddMainDocumentPart();
GenerateMainDocumentPart1Content(mainDocumentPart1);
StylesWithEffectsPart stylesWithEffectsPart1 = mainDocumentPart1.AddNewPart<StylesWithEffectsPart>("rId3");
GenerateStylesWithEffectsPart1Content(stylesWithEffectsPart1);
ThemePart themePart1 = mainDocumentPart1.AddNewPart<ThemePart>("rId7");
GenerateThemePart1Content(themePart1);
StyleDefinitionsPart styleDefinitionsPart1 = mainDocumentPart1.AddNewPart<StyleDefinitionsPart>("rId2");
GenerateStyleDefinitionsPart1Content(styleDefinitionsPart1);
CustomXmlPart customXmlPart1 = mainDocumentPart1.AddNewPart<CustomXmlPart>("application/xml", "rId1");
GenerateCustomXmlPart1Content(customXmlPart1);
CustomXmlPropertiesPart customXmlPropertiesPart1 = customXmlPart1.AddNewPart<CustomXmlPropertiesPart>("rId1");
GenerateCustomXmlPropertiesPart1Content(customXmlPropertiesPart1);
FontTablePart fontTablePart1 = mainDocumentPart1.AddNewPart<FontTablePart>("rId6");
GenerateFontTablePart1Content(fontTablePart1);
WebSettingsPart webSettingsPart1 = mainDocumentPart1.AddNewPart<WebSettingsPart>("rId5");
GenerateWebSettingsPart1Content(webSettingsPart1);
DocumentSettingsPart documentSettingsPart1 = mainDocumentPart1.AddNewPart<DocumentSettingsPart>("rId4");
GenerateDocumentSettingsPart1Content(documentSettingsPart1);
documentSettingsPart1.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate", new System.Uri("file:///D:\\Downloads\\FamilyMergeDoc%20(2).dotx", System.UriKind.Absolute), "rId1");
}
开发者ID:stevesloka,项目名称:bvcms,代码行数:35,代码来源:FamilyDir.cs
示例2: GetText
public string GetText(string docFilePath)
{
try
{
this.package = WordprocessingDocument.Open(docFilePath, true);
StringBuilder sb = new StringBuilder();
OpenXmlElement element = package.MainDocumentPart.Document.Body;
if (element == null)
{
return string.Empty;
}
sb.Append(GetPlainText(element));
return sb.ToString();
}
catch (Exception e)
{
throw;
}
finally
{
GC.Collect();
}
}
开发者ID:zeferreira,项目名称:eDoc,代码行数:26,代码来源:DocParserDocxOpenXML.cs
示例3: ReplaceBookmark
public void ReplaceBookmark(WordprocessingDocument package, string bookmark, string content)
{
IDictionary<String, BookmarkStart> bookmarkMap = new Dictionary<String, BookmarkStart>();
foreach (BookmarkStart bookmarkStart in package.MainDocumentPart.RootElement.Descendants<BookmarkStart>()) {
bookmarkMap[bookmarkStart.Name] = bookmarkStart;
}
foreach (BookmarkStart bookmarkStart in bookmarkMap.Values) {
if (bookmarkStart.Name == bookmark) {
Run bookmarkText = bookmarkStart.NextSibling<Run>();
if (bookmarkText != null) {
bookmarkText.GetFirstChild<Text>().Text = content;
}
else {
var textElement = new Text(content);
var runElement = new Run(textElement);
bookmarkStart.InsertAfterSelf(runElement);
}
}
}
}
开发者ID:FerHenrique,项目名称:Owl,代码行数:25,代码来源:BookmarkReplacer.cs
示例4: CreateParts
// Adds child parts and generates content of the specified part.
private void CreateParts(WordprocessingDocument document)
{
ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);
MainDocumentPart mainDocumentPart1 = document.AddMainDocumentPart();
GenerateMainDocumentPart1Content(mainDocumentPart1);
DocumentSettingsPart documentSettingsPart1 = mainDocumentPart1.AddNewPart<DocumentSettingsPart>("rId3");
GenerateDocumentSettingsPart1Content(documentSettingsPart1);
StyleDefinitionsPart styleDefinitionsPart1 = mainDocumentPart1.AddNewPart<StyleDefinitionsPart>("rId2");
GenerateStyleDefinitionsPart1Content(styleDefinitionsPart1);
CustomXmlPart customXmlPart1 = mainDocumentPart1.AddNewPart<CustomXmlPart>("application/xml", "rId1");
GenerateCustomXmlPart1Content(customXmlPart1);
CustomXmlPropertiesPart customXmlPropertiesPart1 = customXmlPart1.AddNewPart<CustomXmlPropertiesPart>("rId1");
GenerateCustomXmlPropertiesPart1Content(customXmlPropertiesPart1);
ThemePart themePart1 = mainDocumentPart1.AddNewPart<ThemePart>("rId6");
GenerateThemePart1Content(themePart1);
FontTablePart fontTablePart1 = mainDocumentPart1.AddNewPart<FontTablePart>("rId5");
GenerateFontTablePart1Content(fontTablePart1);
WebSettingsPart webSettingsPart1 = mainDocumentPart1.AddNewPart<WebSettingsPart>("rId4");
GenerateWebSettingsPart1Content(webSettingsPart1);
SetPackageProperties(document);
}
开发者ID:CGHill,项目名称:Hard-To-Find,代码行数:32,代码来源:InvoiceCreator.cs
示例5: CreateProcessor
public static GeneralDataProcessor CreateProcessor(WordprocessingDocument document, DCTDataProperty property)
{
if (property is DCTSimpleProperty)
return new SimplePropertyProcessor(document, (DCTSimpleProperty)property);
return new ComplexPropertyProcessor(document, (DCTComplexProperty)property);
}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:7,代码来源:GeneralDataProcessor.cs
示例6: CreateParts
// Adds child parts and generates content of the specified part.
private void CreateParts(WordprocessingDocument document)
{
ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);
MainDocumentPart mainDocumentPart1 = document.AddMainDocumentPart();
GenerateMainDocumentPart1Content(mainDocumentPart1);
FontTablePart fontTablePart1 = mainDocumentPart1.AddNewPart<FontTablePart>("rId8");
GenerateFontTablePart1Content(fontTablePart1);
WebSettingsPart webSettingsPart1 = mainDocumentPart1.AddNewPart<WebSettingsPart>("rId3");
GenerateWebSettingsPart1Content(webSettingsPart1);
DocumentSettingsPart documentSettingsPart1 = mainDocumentPart1.AddNewPart<DocumentSettingsPart>("rId2");
GenerateDocumentSettingsPart1Content(documentSettingsPart1);
StyleDefinitionsPart styleDefinitionsPart1 = mainDocumentPart1.AddNewPart<StyleDefinitionsPart>("rId1");
GenerateStyleDefinitionsPart1Content(styleDefinitionsPart1);
ThemePart themePart1 = mainDocumentPart1.AddNewPart<ThemePart>("rId9");
GenerateThemePart1Content(themePart1);
mainDocumentPart1.AddHyperlinkRelationship(new System.Uri("mailto:[email protected]", System.UriKind.Absolute), true, "rId7");
mainDocumentPart1.AddHyperlinkRelationship(new System.Uri("http://www.shivam.com", System.UriKind.Absolute), true, "rId6");
mainDocumentPart1.AddHyperlinkRelationship(new System.Uri("mailto:[email protected]", System.UriKind.Absolute), true, "rId5");
mainDocumentPart1.AddHyperlinkRelationship(new System.Uri("http://www.google.com", System.UriKind.Absolute), true, "rId4");
SetPackageProperties(document);
}
开发者ID:vijaypaliwal,项目名称:locum,代码行数:30,代码来源:Generateinvoice.cs
示例7: AddFontTablePartToPackage
public FontTablePart AddFontTablePartToPackage(WordprocessingDocument doc)
{
var part = doc.MainDocumentPart.AddNewPart<FontTablePart>();
var root = new Fonts();
root.Save(part);
return part;
}
开发者ID:Jaykul,项目名称:pickles,代码行数:7,代码来源:WordFontApplicator.cs
示例8: WordprocessingDocumentToStream
private static Stream WordprocessingDocumentToStream(WordprocessingDocument wordDoc)
{
MemoryStream mem = new MemoryStream();
using (var resultDoc = WordprocessingDocument.Create(mem, wordDoc.DocumentType))
{
// copy parts from source document to new document
foreach (var part in wordDoc.Parts)
{
OpenXmlPart targetPart = resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId); // that's recursive :-)
}
resultDoc.Package.Flush();
}
//resultDoc.Package.Close(); // must do this (or using), or the zip won't get created properly
mem.Position = 0;
return mem;
// byte[] bytes = new byte[mem.Length];
// mem.Read(bytes, 0, (int)mem.Length);
// mem.Close();
// //FileStream file = new FileStream(@"C:\Users\jharrop\Documents\tmp-test-docx\outs.docx", FileMode.Create, System.IO.FileAccess.Write);
// //byte[] bytes = new byte[mem.Length];
// //mem.Read(bytes, 0, (int)mem.Length);
// //file.Write(bytes, 0, bytes.Length);
// //file.Close();
// //mem.Close();
//return bytes;
}
开发者ID:Abhishek-add,项目名称:docx4j.NET,代码行数:35,代码来源:WordprocessingMLPackageFactory.cs
示例9: CreateParts
// Adds child parts and generates content of the specified part.
private void CreateParts(WordprocessingDocument document)
{
ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);
MainDocumentPart mainDocumentPart1 = document.AddMainDocumentPart();
GenerateMainDocumentPart1Content(mainDocumentPart1);
DocumentSettingsPart documentSettingsPart1 = mainDocumentPart1.AddNewPart<DocumentSettingsPart>("rId3");
GenerateDocumentSettingsPart1Content(documentSettingsPart1);
StylesWithEffectsPart stylesWithEffectsPart1 = mainDocumentPart1.AddNewPart<StylesWithEffectsPart>("rId2");
GenerateStylesWithEffectsPart1Content(stylesWithEffectsPart1);
StyleDefinitionsPart styleDefinitionsPart1 = mainDocumentPart1.AddNewPart<StyleDefinitionsPart>("rId1");
GenerateStyleDefinitionsPart1Content(styleDefinitionsPart1);
ThemePart themePart1 = mainDocumentPart1.AddNewPart<ThemePart>("rId6");
GenerateThemePart1Content(themePart1);
FontTablePart fontTablePart1 = mainDocumentPart1.AddNewPart<FontTablePart>("rId5");
GenerateFontTablePart1Content(fontTablePart1);
WebSettingsPart webSettingsPart1 = mainDocumentPart1.AddNewPart<WebSettingsPart>("rId4");
GenerateWebSettingsPart1Content(webSettingsPart1);
}
开发者ID:stevesloka,项目名称:bvcms,代码行数:28,代码来源:EmployerAddress.cs
示例10: SimplifyMarkup
public static void SimplifyMarkup(WordprocessingDocument doc,
SimplifyMarkupSettings settings)
{
SimplifyMarkupForPart(doc.MainDocumentPart, settings);
SimplifyMarkupForPart(doc.MainDocumentPart.StyleDefinitionsPart, settings);
SimplifyMarkupForPart(doc.MainDocumentPart.StylesWithEffectsPart, settings);
}
开发者ID:mvlasenko,项目名称:TridionDesktopTools,代码行数:7,代码来源:MarkupSimplifier.cs
示例11: GenerateWordDocument
public void GenerateWordDocument(string docName, SessionData sessionObjects, AdditionalData additionalObjects)
{
_sessionObjects = sessionObjects;
_additionalObjects = additionalObjects;
//var openS = new OpenSettings();
//openS.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(
// MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2007);
//using (_wordDocument = WordprocessingDocument.Open(docName, true, openS))
using (_wordDocument = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document))
{
InitilizeDocument();
GenerateTitlePage();
GeneratePageTwo();
GenerateChapterOne();
GenerateChapterTwo();
GenerateChapterThree();
GenerateChapterFour();
GenerateChapterFive();
GenerateChapterSix();
GenerateChapterSeven();
GenerateChapterEight();
GenerateChapterNine();
GenerateChapterTen();
var numberingDefinitionsPart = _mainPart.AddNewPart<NumberingDefinitionsPart>();
numberingDefinitionsPart.Numbering = _numbering;
}
}
开发者ID:silmarion,项目名称:WPDHelper,代码行数:28,代码来源:DocBuilder.cs
示例12: WordDocumentImageManipulator
public WordDocumentImageManipulator(WordprocessingDocument doc)
{
// Open the document as editable.
Document = doc;
}
开发者ID:oghenez,项目名称:trade-software,代码行数:7,代码来源:WordDocumentImageManipulator.cs
示例13: DocxParser
public DocxParser(string fileName)
{
path = Path.GetTempPath() + Path.DirectorySeparatorChar + "tmp-" + DateTime.Now.Ticks.ToString();
File.Copy(fileName, path);
doc = WordprocessingDocument.Open(path, true);
parsedFile = new ContentFile()
{
contentRaw = doc.MainDocumentPart.Document.InnerXml,
contentText = ParseFileContent(XElement.Parse(doc.MainDocumentPart.Document.InnerXml))
};
SetMetadata(MetadataType.Author, doc.PackageProperties.Creator);
SetMetadata(MetadataType.Description, doc.PackageProperties.Description);
SetMetadata(MetadataType.Language, doc.PackageProperties.Language);
SetMetadata(MetadataType.Subject, doc.PackageProperties.Subject);
SetMetadata(MetadataType.Title, doc.PackageProperties.Title);
SetMetadata(MetadataType.Type, doc.PackageProperties.ContentType);
if (doc.PackageProperties.Created.HasValue)
SetMetadata(MetadataType.PublishDate, doc.PackageProperties.Created.Value.ToString());
LoadAllMetadata();
}
开发者ID:sashaMilka,项目名称:MultiReader,代码行数:25,代码来源:DocxParser.cs
示例14: RetrieveListItem
public static string RetrieveListItem(WordprocessingDocument wordDoc,
XElement paragraph, string bulletReplacementString)
{
string pt = paragraph.Elements(W.r).Elements(W.t).Select(e => e.Value)
.StringConcatenate();
NumberingDefinitionsPart numberingDefinitionsPart =
wordDoc.MainDocumentPart.NumberingDefinitionsPart;
if (numberingDefinitionsPart == null)
return null;
StyleDefinitionsPart styleDefinitionsPart = wordDoc.MainDocumentPart
.StyleDefinitionsPart;
if (styleDefinitionsPart == null)
return null;
XDocument numbering = numberingDefinitionsPart.GetXDocument();
XDocument styles = styleDefinitionsPart.GetXDocument();
ListItemInfo listItemInfo = GetListItemInfo(numbering, styles, paragraph);
if (listItemInfo.IsListItem)
{
string lvlText = (string)listItemInfo.Lvl.Elements(W.lvlText)
.Attributes(W.val).FirstOrDefault();
int[] levelNumbers = GetLevelNumbers(numbering, styles, paragraph);
paragraph.AddAnnotation(new LevelNumbers()
{
LevelNumbersArray = levelNumbers
});
string listItem = FormatListItem(listItemInfo.Lvl, levelNumbers, lvlText,
bulletReplacementString);
return listItem;
}
return null;
}
开发者ID:jecabana,项目名称:Portal-Vanity-Daniel-en-stand-by,代码行数:31,代码来源:ListItemRetriever.cs
示例15: CompareDocuments
// todo
// we want overload for this that takes WmlDocument, or whatever new class is.
// also want ability to specify multiple options - a settings object - compare headers, footers, etc.
//
// Returns true if docs are the same, otherwise false.
public static bool CompareDocuments(WordprocessingDocument doc1, WordprocessingDocument doc2)
{
XDocument doc1XDoc = doc1.MainDocumentPart.GetXDocument();
XDocument doc2XDoc = doc2.MainDocumentPart.GetXDocument();
if (CompareOpenXmlElements(doc1XDoc.Root, doc2XDoc.Root) == false)
return false;
// for the current use of this class, only need to compare the main document parts.
#if false
if (doc1.MainDocumentPart.HeaderParts.Count() != doc2.MainDocumentPart.HeaderParts.Count())
return false;
foreach (var pair in doc1
.MainDocumentPart
.HeaderParts
.Zip(doc2.MainDocumentPart.HeaderParts, (d1, d2) =>
new
{
Doc1Header = d1,
Doc2Header = d2,
}))
{
if (CompareOpenXmlElements(pair.Doc1Header.GetXDocument().Root,
pair.Doc2Header.GetXDocument().Root) == false)
return false;
}
if (doc1.MainDocumentPart.FooterParts.Count() != doc2.MainDocumentPart.FooterParts.Count())
return false;
foreach (var pair in doc1
.MainDocumentPart
.FooterParts
.Zip(doc2.MainDocumentPart.FooterParts, (d1, d2) =>
new
{
Doc1Footer = d1,
Doc2Footer = d2,
}))
{
if (CompareOpenXmlElements(pair.Doc1Footer.GetXDocument().Root,
pair.Doc2Footer.GetXDocument().Root) == false)
return false;
}
if ((doc1.MainDocumentPart.FootnotesPart == null) != (doc2.MainDocumentPart.FootnotesPart == null))
return false;
if (doc1.MainDocumentPart.FootnotesPart != null)
{
if (CompareOpenXmlElements(doc1.MainDocumentPart.FootnotesPart.GetXDocument().Root,
doc2.MainDocumentPart.FootnotesPart.GetXDocument().Root) == false)
return false;
}
if ((doc1.MainDocumentPart.EndnotesPart == null) != (doc2.MainDocumentPart.EndnotesPart == null))
return false;
if (doc1.MainDocumentPart.EndnotesPart != null)
{
if (CompareOpenXmlElements(doc1.MainDocumentPart.EndnotesPart.GetXDocument().Root,
doc2.MainDocumentPart.EndnotesPart.GetXDocument().Root) == false)
return false;
}
#endif
return true;
}
开发者ID:jecabana,项目名称:Portal-Vanity-Daniel-en-stand-by,代码行数:65,代码来源:DocumentComparer.cs
示例16: OpenXmlHelper
/// <summary>
/// Constructor for creating a new document.
/// </summary>
/// <param name="filePath">Path to where the new file should be created.</param>
public OpenXmlHelper(string filePath)
{
_filePath = filePath;
if (File.Exists(filePath))
{
_package = WordprocessingDocument.Open(filePath, true);
//TODO: ADD SEPERATOR TO OPENED DOCUMENT BEFORE APPENDING
Debug.WriteLine("Opened existing file {0}", filePath);
_document = _package.MainDocumentPart.Document;
}
else
{
_package = WordprocessingDocument.Create(_filePath, WordprocessingDocumentType.Document);
if (File.Exists(_filePath))
{
MainDocumentPart main = _package.AddMainDocumentPart();
main.Document = new Document();
Document document = main.Document;
Body body = document.AppendChild(new Body());
_document = _package.MainDocumentPart.Document;
_document.Save();
}
else
{
Debug.WriteLine("Failed to create the file: {0}", filePath);
}
}
}
开发者ID:vandersmissenc,项目名称:OpenXmlDocumentGenerator,代码行数:32,代码来源:OpenXmlHelper.cs
示例17: AddTable
public void AddTable(WordprocessingDocument package, DataTable table, TableStyle tableStyle)
{
Body body = package.MainDocumentPart.Document.Body;
// Create an empty table.
Table tbl = new Table();
// Set table width
SetTableWidth(tableStyle, tbl);
// Create a TableProperties object and specify its border information.
TableProperties tblProp = CreateTableProperties();
// Set table alignment
SetTableAlignment(tableStyle.Alignment, tblProp);
// Append the TableProperties object to the empty table.
tbl.AppendChild<TableProperties>(tblProp);
if (tableStyle.ShowTitle) {
AddTitleRow(table, tableStyle, tbl);
}
if (tableStyle.ShowHeader) {
AddHeaderRow(table, tbl, tableStyle);
}
AddRows(table, tableStyle, tbl, tblProp);
// Append the final table to the document body
body.Append(tbl);
}
开发者ID:FerHenrique,项目名称:Owl,代码行数:32,代码来源:TableCreator.cs
示例18: DocxDocumentTableSchemeBuilder
internal DocxDocumentTableSchemeBuilder(WordprocessingDocument document, TableProperties contextTableProperties)
: base(document)
{
table = new Table();
if (contextTableProperties == null)
{
var borderType = new EnumValue<BorderValues>(BorderValues.Thick);
var tblProp = new TableProperties(
new TableBorders(
new TopBorder {Val = borderType, Size = 1},
new BottomBorder {Val = borderType, Size = 1},
new LeftBorder {Val = borderType, Size = 1},
new RightBorder {Val = borderType, Size = 1},
new InsideHorizontalBorder {Val = borderType, Size = 1},
new InsideVerticalBorder {Val = borderType, Size = 1}
)
);
table.AppendChild(tblProp);
}
else
table.AppendChild(contextTableProperties);
headerRow = new TableRow();
table.AppendChild(headerRow);
Aggregation.Add(table);
}
开发者ID:AlexanderByndyu,项目名称:TabulaRasa,代码行数:27,代码来源:DocxDocumentTableSchemeBuilder.cs
示例19: ApplyHeaderAndFooter
public void ApplyHeaderAndFooter(WordprocessingDocument wordProcessingDocument)
{
var headerPart = wordProcessingDocument.MainDocumentPart.AddNewPart<HeaderPart>();
this.ApplyHeader(headerPart);
var footerPart = wordProcessingDocument.MainDocumentPart.AddNewPart<FooterPart>();
this.ApplyFooter(footerPart);
}
开发者ID:vavavivi,项目名称:pickles,代码行数:8,代码来源:WordHeaderFooterFormatter.cs
示例20: AddBackgroundShapeElement
/// <summary>
/// Adds a displayBackgroundShape element to the settings file
/// </summary>
public static void AddBackgroundShapeElement(WordprocessingDocument document)
{
XDocument settingsDocument = document.MainDocumentPart.DocumentSettingsPart.GetXDocument();
settingsDocument.Root.Add(
new XElement(ns + "displayBackgroundShape")
);
document.MainDocumentPart.DocumentSettingsPart.PutXDocument();
}
开发者ID:jecabana,项目名称:Portal-Vanity-Daniel-en-stand-by,代码行数:11,代码来源:SettingAccessor.cs
注:本文中的WordprocessingDocument类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论