| <?xml version="1.0" encoding="utf-8"?> | |||||
| <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||||
| <PropertyGroup> | |||||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||||
| <Platform Condition=" '$(Platform)' == '' ">x86</Platform> | |||||
| <ProductVersion>8.0.30703</ProductVersion> | |||||
| <SchemaVersion>2.0</SchemaVersion> | |||||
| <ProjectGuid>{5C3408FE-0F80-4093-9C2B-1C46B4358F72}</ProjectGuid> | |||||
| <OutputType>Exe</OutputType> | |||||
| <AppDesignerFolder>Properties</AppDesignerFolder> | |||||
| <RootNamespace>ConsoleApplication1</RootNamespace> | |||||
| <AssemblyName>ConsoleApplication1</AssemblyName> | |||||
| <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | |||||
| <TargetFrameworkProfile>Client</TargetFrameworkProfile> | |||||
| <FileAlignment>512</FileAlignment> | |||||
| <SccProjectName>SAK</SccProjectName> | |||||
| <SccLocalPath>SAK</SccLocalPath> | |||||
| <SccAuxPath>SAK</SccAuxPath> | |||||
| <SccProvider>SAK</SccProvider> | |||||
| </PropertyGroup> | |||||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | |||||
| <PlatformTarget>x86</PlatformTarget> | |||||
| <DebugSymbols>true</DebugSymbols> | |||||
| <DebugType>full</DebugType> | |||||
| <Optimize>false</Optimize> | |||||
| <OutputPath>bin\Debug\</OutputPath> | |||||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | |||||
| <ErrorReport>prompt</ErrorReport> | |||||
| <WarningLevel>4</WarningLevel> | |||||
| </PropertyGroup> | |||||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | |||||
| <PlatformTarget>x86</PlatformTarget> | |||||
| <DebugType>pdbonly</DebugType> | |||||
| <Optimize>true</Optimize> | |||||
| <OutputPath>bin\Release\</OutputPath> | |||||
| <DefineConstants>TRACE</DefineConstants> | |||||
| <ErrorReport>prompt</ErrorReport> | |||||
| <WarningLevel>4</WarningLevel> | |||||
| </PropertyGroup> | |||||
| <ItemGroup> | |||||
| <Reference Include="System" /> | |||||
| <Reference Include="System.Core" /> | |||||
| <Reference Include="System.Xml.Linq" /> | |||||
| <Reference Include="System.Data.DataSetExtensions" /> | |||||
| <Reference Include="Microsoft.CSharp" /> | |||||
| <Reference Include="System.Data" /> | |||||
| <Reference Include="System.Xml" /> | |||||
| <Reference Include="WindowsBase" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <Compile Include="Program.cs" /> | |||||
| <Compile Include="Properties\AssemblyInfo.cs" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <ProjectReference Include="..\DocX\DocX.csproj"> | |||||
| <Project>{E863D072-AA8B-4108-B5F1-785241B37F67}</Project> | |||||
| <Name>DocX</Name> | |||||
| </ProjectReference> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <None Include="data\load-error.docx" /> | |||||
| <None Include="data\Test-01.docx" /> | |||||
| </ItemGroup> | |||||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||||
| <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |||||
| Other similar extension points exist, see Microsoft.Common.targets. | |||||
| <Target Name="BeforeBuild"> | |||||
| </Target> | |||||
| <Target Name="AfterBuild"> | |||||
| </Target> | |||||
| --> | |||||
| </Project> |
| "" | |||||
| { | |||||
| "FILE_VERSION" = "9237" | |||||
| "ENLISTMENT_CHOICE" = "NEVER" | |||||
| "PROJECT_FILE_RELATIVE_PATH" = "" | |||||
| "NUMBER_OF_EXCLUDED_FILES" = "0" | |||||
| "ORIGINAL_PROJECT_FILE_PATH" = "" | |||||
| "NUMBER_OF_NESTED_PROJECTS" = "0" | |||||
| "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" | |||||
| } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using Novacode; | |||||
| using System.IO.Packaging; | |||||
| using System.Diagnostics; | |||||
| namespace ConsoleApplication1 | |||||
| { | |||||
| class Program | |||||
| { | |||||
| static void Main(string[] args) | |||||
| { | |||||
| //// Testing constants | |||||
| //const string package_part_document = "/word/document.xml"; | |||||
| //const string package_part_header_first = "/word/header3.xml"; | |||||
| //const string package_part_header_odd = "/word/header2.xml"; | |||||
| //const string package_part_header_even = "/word/header1.xml"; | |||||
| //const string package_part_footer_first = "/word/footer3.xml"; | |||||
| //const string package_part_footer_odd = "/word/footer2.xml"; | |||||
| //const string package_part_footer_even = "/word/footer1.xml"; | |||||
| //// Load Test-01.docx | |||||
| //using (DocX document = DocX.Load("../../data/Test-01.docx")) | |||||
| //{ | |||||
| // // Get the headers from the document. | |||||
| // Headers headers = document.Headers; Debug.Assert(headers != null); | |||||
| // Header header_first = headers.first; Debug.Assert(header_first != null); | |||||
| // Header header_odd = headers.odd; Debug.Assert(header_odd != null); | |||||
| // Header header_even = headers.even; Debug.Assert(header_even != null); | |||||
| // // Get the footers from the document. | |||||
| // Footers footers = document.Footers; Debug.Assert(footers != null); | |||||
| // Footer footer_first = footers.first; Debug.Assert(footer_first != null); | |||||
| // Footer footer_odd = footers.odd; Debug.Assert(footer_odd != null); | |||||
| // Footer footer_even = footers.even; Debug.Assert(footer_even != null); | |||||
| // // Its important that each Paragraph knows the PackagePart it belongs to. | |||||
| // document.Paragraphs.ForEach(p => Debug.Assert(p.PackagePart.Uri.ToString() == package_part_document)); | |||||
| // header_first.Paragraphs.ForEach(p => Debug.Assert(p.PackagePart.Uri.ToString() == package_part_header_first)); | |||||
| // header_odd.Paragraphs.ForEach(p => Debug.Assert(p.PackagePart.Uri.ToString() == package_part_header_odd)); | |||||
| // header_even.Paragraphs.ForEach(p => Debug.Assert(p.PackagePart.Uri.ToString() == package_part_header_even)); | |||||
| // footer_first.Paragraphs.ForEach(p => Debug.Assert(p.PackagePart.Uri.ToString() == package_part_footer_first)); | |||||
| // footer_odd.Paragraphs.ForEach(p => Debug.Assert(p.PackagePart.Uri.ToString() == package_part_footer_odd)); | |||||
| // footer_even.Paragraphs.ForEach(p => Debug.Assert(p.PackagePart.Uri.ToString() == package_part_footer_even)); | |||||
| //} | |||||
| } | |||||
| } | |||||
| } |
| using System.Reflection; | |||||
| using System.Runtime.CompilerServices; | |||||
| using System.Runtime.InteropServices; | |||||
| // General Information about an assembly is controlled through the following | |||||
| // set of attributes. Change these attribute values to modify the information | |||||
| // associated with an assembly. | |||||
| [assembly: AssemblyTitle("ConsoleApplication1")] | |||||
| [assembly: AssemblyDescription("")] | |||||
| [assembly: AssemblyConfiguration("")] | |||||
| [assembly: AssemblyCompany("")] | |||||
| [assembly: AssemblyProduct("ConsoleApplication1")] | |||||
| [assembly: AssemblyCopyright("Copyright © 2010")] | |||||
| [assembly: AssemblyTrademark("")] | |||||
| [assembly: AssemblyCulture("")] | |||||
| // Setting ComVisible to false makes the types in this assembly not visible | |||||
| // to COM components. If you need to access a type in this assembly from | |||||
| // COM, set the ComVisible attribute to true on that type. | |||||
| [assembly: ComVisible(false)] | |||||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | |||||
| [assembly: Guid("4fbe30d8-8d81-4dc4-adc2-58297c152631")] | |||||
| // Version information for an assembly consists of the following four values: | |||||
| // | |||||
| // Major Version | |||||
| // Minor Version | |||||
| // Build Number | |||||
| // Revision | |||||
| // | |||||
| // You can specify all the values or you can default the Build and Revision Numbers | |||||
| // by using the '*' as shown below: | |||||
| // [assembly: AssemblyVersion("1.0.*")] | |||||
| [assembly: AssemblyVersion("1.0.0.0")] | |||||
| [assembly: AssemblyFileVersion("1.0.0.0")] |
| | | ||||
| Microsoft Visual Studio Solution File, Format Version 10.00 | |||||
| # Visual Studio 2008 | |||||
| Microsoft Visual Studio Solution File, Format Version 11.00 | |||||
| # Visual Studio 2010 | |||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DF41F5CE-8BCB-40CC-835F-54A3DB7D802F}" | |||||
| ProjectSection(SolutionItems) = preProject | |||||
| DocX.vsmdi = DocX.vsmdi | |||||
| Local.testsettings = Local.testsettings | |||||
| TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings | |||||
| EndProjectSection | |||||
| EndProject | |||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocX", "DocX\DocX.csproj", "{E863D072-AA8B-4108-B5F1-785241B37F67}" | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocX", "DocX\DocX.csproj", "{E863D072-AA8B-4108-B5F1-785241B37F67}" | ||||
| EndProject | EndProject | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DF41F5CE-8BCB-40CC-835F-54A3DB7D802F}" | |||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.csproj", "{5C3408FE-0F80-4093-9C2B-1C46B4358F72}" | |||||
| EndProject | |||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}" | |||||
| EndProject | EndProject | ||||
| Global | Global | ||||
| GlobalSection(TeamFoundationVersionControl) = preSolution | GlobalSection(TeamFoundationVersionControl) = preSolution | ||||
| SccNumberOfProjects = 3 | |||||
| SccNumberOfProjects = 4 | |||||
| SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} | SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} | ||||
| SccTeamFoundationServer = https://tfs08.codeplex.com/ | |||||
| SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs08 | |||||
| SccLocalPath0 = . | SccLocalPath0 = . | ||||
| SccProjectUniqueName1 = DocX\\DocX.csproj | SccProjectUniqueName1 = DocX\\DocX.csproj | ||||
| SccProjectName1 = DocX | SccProjectName1 = DocX | ||||
| SccProjectUniqueName2 = ConsoleApplication1\\ConsoleApplication1.csproj | SccProjectUniqueName2 = ConsoleApplication1\\ConsoleApplication1.csproj | ||||
| SccProjectName2 = ConsoleApplication1 | SccProjectName2 = ConsoleApplication1 | ||||
| SccLocalPath2 = ConsoleApplication1 | SccLocalPath2 = ConsoleApplication1 | ||||
| SccProjectUniqueName3 = UnitTests\\UnitTests.csproj | |||||
| SccProjectName3 = UnitTests | |||||
| SccLocalPath3 = UnitTests | |||||
| EndGlobalSection | |||||
| GlobalSection(TestCaseManagementSettings) = postSolution | |||||
| CategoryFile = DocX.vsmdi | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| Debug|Any CPU = Debug|Any CPU | Debug|Any CPU = Debug|Any CPU | ||||
| Debug|Mixed Platforms = Debug|Mixed Platforms | |||||
| Debug|x86 = Debug|x86 | |||||
| Release|Any CPU = Release|Any CPU | Release|Any CPU = Release|Any CPU | ||||
| Release|Mixed Platforms = Release|Mixed Platforms | |||||
| Release|x86 = Release|x86 | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | {E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|Any CPU.Build.0 = Debug|Any CPU | {E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | |||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | |||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Debug|x86.ActiveCfg = Debug|Any CPU | |||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Release|Any CPU.ActiveCfg = Release|Any CPU | {E863D072-AA8B-4108-B5F1-785241B37F67}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Release|Any CPU.Build.0 = Release|Any CPU | {E863D072-AA8B-4108-B5F1-785241B37F67}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU | |||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Release|Mixed Platforms.Build.0 = Release|Any CPU | |||||
| {E863D072-AA8B-4108-B5F1-785241B37F67}.Release|x86.ActiveCfg = Release|Any CPU | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Debug|Any CPU.ActiveCfg = Debug|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Debug|Mixed Platforms.Build.0 = Debug|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Debug|x86.ActiveCfg = Debug|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Debug|x86.Build.0 = Debug|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Release|Any CPU.ActiveCfg = Release|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Release|Mixed Platforms.ActiveCfg = Release|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Release|Mixed Platforms.Build.0 = Release|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Release|x86.ActiveCfg = Release|x86 | |||||
| {5C3408FE-0F80-4093-9C2B-1C46B4358F72}.Release|x86.Build.0 = Release|x86 | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Debug|x86.ActiveCfg = Debug|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Release|Mixed Platforms.Build.0 = Release|Any CPU | |||||
| {3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}.Release|x86.ActiveCfg = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE |
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"> | |||||
| <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"> | |||||
| <RunConfiguration id="95fe5b2d-3af6-4f81-a23a-86c45b1f95a1" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> | |||||
| </TestList> | |||||
| </TestLists> |
| public virtual void ReplaceText(string oldValue, string newValue, bool trackChanges) | public virtual void ReplaceText(string oldValue, string newValue, bool trackChanges) | ||||
| { | { | ||||
| ReplaceText(oldValue, newValue, trackChanges, false, false, RegexOptions.None); | |||||
| ReplaceText(oldValue, newValue, false, false, trackChanges, RegexOptions.None); | |||||
| } | } | ||||
| public virtual void ReplaceText(string oldValue, string newValue, bool includeHeaders, bool includeFooters, bool trackChanges) | public virtual void ReplaceText(string oldValue, string newValue, bool includeHeaders, bool includeFooters, bool trackChanges) | ||||
| ); | ); | ||||
| } | } | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return p; | return p; | ||||
| } | } | ||||
| else | else | ||||
| Xml.Add(newParagraph); | Xml.Add(newParagraph); | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return newParagraph; | return newParagraph; | ||||
| } | } | ||||
| Xml.Add(newParagraph); | Xml.Add(newParagraph); | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return Paragraphs.Last(); | return Paragraphs.Last(); | ||||
| } | } | ||||
| // Get the word\settings.xml part | // Get the word\settings.xml part | ||||
| internal PackagePart settingsPart; | internal PackagePart settingsPart; | ||||
| #region Private instance variables defined foreach DocX object | |||||
| // The collection of Paragraphs in this document. | |||||
| internal List<Paragraph> paragraphs = new List<Paragraph>(); | |||||
| #endregion | |||||
| #region Internal variables defined foreach DocX object | #region Internal variables defined foreach DocX object | ||||
| // Object representation of the .docx | // Object representation of the .docx | ||||
| internal Package package; | internal Package package; | ||||
| get | get | ||||
| { | { | ||||
| string text = string.Empty; | string text = string.Empty; | ||||
| foreach (Paragraph p in paragraphs) | |||||
| foreach (Paragraph p in Paragraphs) | |||||
| { | { | ||||
| text += p.Text + "\n"; | text += p.Text + "\n"; | ||||
| } | } | ||||
| foreach (var r in externalHeaderAndFooterReferences.ToList()) | foreach (var r in externalHeaderAndFooterReferences.ToList()) | ||||
| r.Remove(); | r.Remove(); | ||||
| #endregion | #endregion | ||||
| HelperFunctions.RebuildParagraphs(this); | |||||
| } | } | ||||
| XElement newTable = HelperFunctions.CreateTable(rowCount, coloumnCount); | XElement newTable = HelperFunctions.CreateTable(rowCount, coloumnCount); | ||||
| mainDoc.Descendants(XName.Get("body", DocX.w.NamespaceName)).First().Add(newTable); | mainDoc.Descendants(XName.Get("body", DocX.w.NamespaceName)).First().Add(newTable); | ||||
| HelperFunctions.RebuildParagraphs(this); | |||||
| return new Table(this, newTable); | return new Table(this, newTable); | ||||
| } | } | ||||
| Table newTable = new Table(this, newXElement); | Table newTable = new Table(this, newXElement); | ||||
| newTable.Design = t.Design; | newTable.Design = t.Design; | ||||
| HelperFunctions.RebuildParagraphs(this); | |||||
| return newTable; | return newTable; | ||||
| } | } | ||||
| ); | ); | ||||
| } | } | ||||
| HelperFunctions.RebuildParagraphs(this); | |||||
| return new Table(this, newTable); | return new Table(this, newTable); | ||||
| } | } | ||||
| using (TextReader tr = new StreamReader(document.mainPart.GetStream(FileMode.Open, FileAccess.Read))) | using (TextReader tr = new StreamReader(document.mainPart.GetStream(FileMode.Open, FileAccess.Read))) | ||||
| document.mainDoc = XDocument.Load(tr, LoadOptions.PreserveWhitespace); | document.mainDoc = XDocument.Load(tr, LoadOptions.PreserveWhitespace); | ||||
| HelperFunctions.RebuildParagraphs(document); | |||||
| #endregion | #endregion | ||||
| Headers headers = new Headers(); | Headers headers = new Headers(); | ||||
| return p; | return p; | ||||
| } | } | ||||
| public override List<Paragraph> Paragraphs | |||||
| { | |||||
| get | |||||
| { | |||||
| List<Paragraph> l = base.Paragraphs; | |||||
| l.ForEach(x => x.PackagePart = mainPart); | |||||
| return l; | |||||
| } | |||||
| } | |||||
| #region IDisposable Members | #region IDisposable Members | ||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||
| <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||||
| <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||||
| <PropertyGroup> | <PropertyGroup> | ||||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||||
| </StartupObject> | </StartupObject> | ||||
| <SignAssembly>false</SignAssembly> | <SignAssembly>false</SignAssembly> | ||||
| <AssemblyOriginatorKeyFile>StrongNameKey.pfx</AssemblyOriginatorKeyFile> | <AssemblyOriginatorKeyFile>StrongNameKey.pfx</AssemblyOriginatorKeyFile> | ||||
| <FileUpgradeFlags> | |||||
| </FileUpgradeFlags> | |||||
| <OldToolsVersion>3.5</OldToolsVersion> | |||||
| <UpgradeBackupLocation /> | |||||
| <PublishUrl>publish\</PublishUrl> | |||||
| <Install>true</Install> | |||||
| <InstallFrom>Disk</InstallFrom> | |||||
| <UpdateEnabled>false</UpdateEnabled> | |||||
| <UpdateMode>Foreground</UpdateMode> | |||||
| <UpdateInterval>7</UpdateInterval> | |||||
| <UpdateIntervalUnits>Days</UpdateIntervalUnits> | |||||
| <UpdatePeriodically>false</UpdatePeriodically> | |||||
| <UpdateRequired>false</UpdateRequired> | |||||
| <MapFileExtensions>true</MapFileExtensions> | |||||
| <ApplicationRevision>0</ApplicationRevision> | |||||
| <ApplicationVersion>1.0.0.%2a</ApplicationVersion> | |||||
| <IsWebBootstrapper>false</IsWebBootstrapper> | |||||
| <UseApplicationTrust>false</UseApplicationTrust> | |||||
| <BootstrapperEnabled>true</BootstrapperEnabled> | |||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||||
| <DebugSymbols>true</DebugSymbols> | <DebugSymbols>true</DebugSymbols> | ||||
| <ErrorReport>prompt</ErrorReport> | <ErrorReport>prompt</ErrorReport> | ||||
| <WarningLevel>4</WarningLevel> | <WarningLevel>4</WarningLevel> | ||||
| <DocumentationFile>bin\Debug\DocX.xml</DocumentationFile> | <DocumentationFile>bin\Debug\DocX.xml</DocumentationFile> | ||||
| <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> | |||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||||
| <DebugType>pdbonly</DebugType> | <DebugType>pdbonly</DebugType> | ||||
| <DefineConstants>TRACE</DefineConstants> | <DefineConstants>TRACE</DefineConstants> | ||||
| <ErrorReport>prompt</ErrorReport> | <ErrorReport>prompt</ErrorReport> | ||||
| <WarningLevel>4</WarningLevel> | <WarningLevel>4</WarningLevel> | ||||
| <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> | |||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <Reference Include="System" /> | <Reference Include="System" /> | ||||
| <EmbeddedResource Include="Resources\default_styles.xml.gz" /> | <EmbeddedResource Include="Resources\default_styles.xml.gz" /> | ||||
| <EmbeddedResource Include="Resources\styles.xml.gz" /> | <EmbeddedResource Include="Resources\styles.xml.gz" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | |||||
| <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> | |||||
| <Visible>False</Visible> | |||||
| <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> | |||||
| <Install>false</Install> | |||||
| </BootstrapperPackage> | |||||
| <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> | |||||
| <Visible>False</Visible> | |||||
| <ProductName>.NET Framework 3.5 SP1</ProductName> | |||||
| <Install>true</Install> | |||||
| </BootstrapperPackage> | |||||
| <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> | |||||
| <Visible>False</Visible> | |||||
| <ProductName>Windows Installer 3.1</ProductName> | |||||
| <Install>true</Install> | |||||
| </BootstrapperPackage> | |||||
| </ItemGroup> | |||||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||||
| <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||||
| Other similar extension points exist, see Microsoft.Common.targets. | Other similar extension points exist, see Microsoft.Common.targets. |
| return p; | return p; | ||||
| } | } | ||||
| public override List<Paragraph> Paragraphs | |||||
| { | |||||
| get | |||||
| { | |||||
| List<Paragraph> l = base.Paragraphs; | |||||
| l.ForEach(x => x.PackagePart = mainPart); | |||||
| return l; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } |
| return p; | return p; | ||||
| } | } | ||||
| public override List<Paragraph> Paragraphs | |||||
| { | |||||
| get | |||||
| { | |||||
| List<Paragraph> l = base.Paragraphs; | |||||
| l.ForEach(x => x.PackagePart = mainPart); | |||||
| return l; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } |
| return new XElement[] { before, after }; | return new XElement[] { before, after }; | ||||
| } | } | ||||
| static internal void RebuildParagraphs(DocX document) | |||||
| { | |||||
| document.paragraphLookup.Clear(); | |||||
| document.paragraphs.Clear(); | |||||
| // Get the runs in this paragraph | |||||
| IEnumerable<XElement> paras = document.mainDoc.Descendants(XName.Get("p", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")); | |||||
| int startIndex = 0; | |||||
| // Loop through each run in this paragraph | |||||
| foreach (XElement par in paras) | |||||
| { | |||||
| Paragraph xp = new Paragraph(document, par, startIndex); | |||||
| // Add to paragraph list | |||||
| document.paragraphs.Add(xp); | |||||
| // Only add runs which contain text | |||||
| if (Paragraph.GetElementTextLength(par) > 0) | |||||
| { | |||||
| document.paragraphLookup.Add(xp.endIndex, xp); | |||||
| startIndex = xp.endIndex; | |||||
| } | |||||
| } | |||||
| } | |||||
| /// <!-- | /// <!-- | ||||
| /// Bug found and fixed by trnilse. To see the change, | /// Bug found and fixed by trnilse. To see the change, | ||||
| /// please compare this release to the previous release using TFS compare. | /// please compare this release to the previous release using TFS compare. |
| internal int startIndex, endIndex; | internal int startIndex, endIndex; | ||||
| // A collection of Images in this Paragraph | |||||
| private List<Picture> pictures; | |||||
| /// <summary> | /// <summary> | ||||
| /// Returns a list of all Pictures in a Paragraph. | /// Returns a list of all Pictures in a Paragraph. | ||||
| /// </summary> | /// </summary> | ||||
| this.endIndex = startIndex + GetElementTextLength(xml); | this.endIndex = startIndex + GetElementTextLength(xml); | ||||
| BuildRunLookup(xml); | BuildRunLookup(xml); | ||||
| // Get all of the images in this document | |||||
| pictures = | |||||
| ( | |||||
| from i in xml.Descendants(XName.Get("drawing", DocX.w.NamespaceName)) | |||||
| let id = | |||||
| ( | |||||
| from e in Xml.Descendants() | |||||
| where e.Name.LocalName.Equals("blip") | |||||
| select e.Attribute(XName.Get("embed", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")).Value | |||||
| ).Single() | |||||
| let img = new Image(Document, mainPart.GetRelationship(id)) | |||||
| select new Picture(Document, i, img) | |||||
| ).ToList(); | |||||
| RebuildDocProperties(); | RebuildDocProperties(); | ||||
| #region It's possible that a Paragraph may have pStyle references | #region It's possible that a Paragraph may have pStyle references | ||||
| } | } | ||||
| } | } | ||||
| #endregion | #endregion | ||||
| #region Pictures | |||||
| // Check if this Paragraph contains any Pictures | |||||
| List<string> pictureElementIDs = | |||||
| ( | |||||
| from d in xml.Descendants() | |||||
| let embed = d.Attribute(XName.Get("embed", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")) | |||||
| where embed != null | |||||
| select embed.Value | |||||
| ).ToList(); | |||||
| #endregion | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| runLookup = null; | runLookup = null; | ||||
| } | } | ||||
| } | } | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| } | } | ||||
| internal void BuildRunLookup(XElement p) | internal void BuildRunLookup(XElement p) | ||||
| { | { | ||||
| Picture p = CreatePicture(Document, imageID, name, description); | Picture p = CreatePicture(Document, imageID, name, description); | ||||
| Xml.Add(p.Xml); | Xml.Add(p.Xml); | ||||
| pictures.Add(p); | |||||
| return p; | return p; | ||||
| } | } | ||||
| runLookup.Clear(); | runLookup.Clear(); | ||||
| BuildRunLookup(Xml); | BuildRunLookup(Xml); | ||||
| HelperFunctions.RenumberIDs(Document); | HelperFunctions.RenumberIDs(Document); | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| } | } | ||||
| /// <summary> | /// <summary> |
| XElement newlyInserted = Xml.ElementsBeforeSelf().First(); | XElement newlyInserted = Xml.ElementsBeforeSelf().First(); | ||||
| p.Xml = newlyInserted; | p.Xml = newlyInserted; | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return p; | return p; | ||||
| } | } | ||||
| XElement newlyInserted = Xml.ElementsAfterSelf().First(); | XElement newlyInserted = Xml.ElementsAfterSelf().First(); | ||||
| p.Xml = newlyInserted; | p.Xml = newlyInserted; | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return p; | return p; | ||||
| } | } | ||||
| XElement newlyInserted = Xml.ElementsBeforeSelf().First(); | XElement newlyInserted = Xml.ElementsBeforeSelf().First(); | ||||
| Paragraph p = new Paragraph(Document, newlyInserted, -1); | Paragraph p = new Paragraph(Document, newlyInserted, -1); | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return p; | return p; | ||||
| } | } | ||||
| XElement newlyInserted = Xml.ElementsAfterSelf().First(); | XElement newlyInserted = Xml.ElementsAfterSelf().First(); | ||||
| Paragraph p = new Paragraph(Document, newlyInserted, -1); | Paragraph p = new Paragraph(Document, newlyInserted, -1); | ||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return p; | return p; | ||||
| } | } | ||||
| Xml.AddAfterSelf(newTable); | Xml.AddAfterSelf(newTable); | ||||
| XElement newlyInserted = Xml.ElementsAfterSelf().First(); | XElement newlyInserted = Xml.ElementsAfterSelf().First(); | ||||
| ////DocX.RebuildTables(Document); | |||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return new Table(Document, newlyInserted); | return new Table(Document, newlyInserted); | ||||
| } | } | ||||
| XElement newlyInserted = Xml.ElementsAfterSelf().First(); | XElement newlyInserted = Xml.ElementsAfterSelf().First(); | ||||
| t.Xml = newlyInserted; | t.Xml = newlyInserted; | ||||
| //DocX.RebuildTables(Document); | |||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return t; | return t; | ||||
| } | } | ||||
| Xml.AddBeforeSelf(newTable); | Xml.AddBeforeSelf(newTable); | ||||
| XElement newlyInserted = Xml.ElementsBeforeSelf().First(); | XElement newlyInserted = Xml.ElementsBeforeSelf().First(); | ||||
| //DocX.RebuildTables(Document); | |||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return new Table(Document, newlyInserted); | return new Table(Document, newlyInserted); | ||||
| } | } | ||||
| XElement newlyInserted = Xml.ElementsBeforeSelf().First(); | XElement newlyInserted = Xml.ElementsBeforeSelf().First(); | ||||
| t.Xml = newlyInserted; | t.Xml = newlyInserted; | ||||
| //DocX.RebuildTables(Document); | |||||
| HelperFunctions.RebuildParagraphs(Document); | |||||
| return t; | return t; | ||||
| } | } |
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <TestSettings name="Local" id="95fe5b2d-3af6-4f81-a23a-86c45b1f95a1" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"> | |||||
| <Description>These are default test settings for a local test run.</Description> | |||||
| <Deployment enabled="false" /> | |||||
| <Execution> | |||||
| <TestTypeSpecific /> | |||||
| <AgentRule name="Execution Agents"> | |||||
| </AgentRule> | |||||
| </Execution> | |||||
| </TestSettings> |
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <TestSettings name="Trace and Test Impact" enableDefaultDataCollectors="true" id="ddea5473-b23c-4e19-9fc6-bd924ed99e12" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"> | |||||
| <Description>These are test settings for Trace and Test Impact.</Description> | |||||
| <Execution> | |||||
| <TestTypeSpecific /> | |||||
| <AgentRule name="Execution Agents"> | |||||
| </AgentRule> | |||||
| </Execution> | |||||
| </TestSettings> |
| using System.Reflection; | |||||
| using System.Runtime.CompilerServices; | |||||
| using System.Runtime.InteropServices; | |||||
| // General Information about an assembly is controlled through the following | |||||
| // set of attributes. Change these attribute values to modify the information | |||||
| // associated with an assembly. | |||||
| [assembly: AssemblyTitle("UnitTests")] | |||||
| [assembly: AssemblyDescription("")] | |||||
| [assembly: AssemblyConfiguration("")] | |||||
| [assembly: AssemblyCompany("")] | |||||
| [assembly: AssemblyProduct("UnitTests")] | |||||
| [assembly: AssemblyCopyright("Copyright © 2010")] | |||||
| [assembly: AssemblyTrademark("")] | |||||
| [assembly: AssemblyCulture("")] | |||||
| // Setting ComVisible to false makes the types in this assembly not visible | |||||
| // to COM components. If you need to access a type in this assembly from | |||||
| // COM, set the ComVisible attribute to true on that type. | |||||
| [assembly: ComVisible(false)] | |||||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | |||||
| [assembly: Guid("63e90d26-1aa6-42b1-904d-fd112b6e8d44")] | |||||
| // Version information for an assembly consists of the following four values: | |||||
| // | |||||
| // Major Version | |||||
| // Minor Version | |||||
| // Build Number | |||||
| // Revision | |||||
| // | |||||
| // You can specify all the values or you can default the Build and Revision Numbers | |||||
| // by using the '*' as shown below: | |||||
| [assembly: AssemblyVersion("1.0.0.0")] | |||||
| [assembly: AssemblyFileVersion("1.0.0.0")] |
| using System; | |||||
| using System.Text; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
| using Novacode; | |||||
| using System.Diagnostics; | |||||
| namespace UnitTests | |||||
| { | |||||
| /// <summary> | |||||
| /// Summary description for UnitTest1 | |||||
| /// </summary> | |||||
| [TestClass] | |||||
| public class UnitTest1 | |||||
| { | |||||
| public UnitTest1() | |||||
| { | |||||
| TestMethod1(); | |||||
| } | |||||
| private TestContext testContextInstance; | |||||
| /// <summary> | |||||
| ///Gets or sets the test context which provides | |||||
| ///information about and functionality for the current test run. | |||||
| ///</summary> | |||||
| public TestContext TestContext | |||||
| { | |||||
| get | |||||
| { | |||||
| return testContextInstance; | |||||
| } | |||||
| set | |||||
| { | |||||
| testContextInstance = value; | |||||
| } | |||||
| } | |||||
| #region Additional test attributes | |||||
| // | |||||
| // You can use the following additional attributes as you write your tests: | |||||
| // | |||||
| // Use ClassInitialize to run code before running the first test in the class | |||||
| // [ClassInitialize()] | |||||
| // public static void MyClassInitialize(TestContext testContext) { } | |||||
| // | |||||
| // Use ClassCleanup to run code after all tests in a class have run | |||||
| // [ClassCleanup()] | |||||
| // public static void MyClassCleanup() { } | |||||
| // | |||||
| // Use TestInitialize to run code before running each test | |||||
| // [TestInitialize()] | |||||
| // public void MyTestInitialize() { } | |||||
| // | |||||
| // Use TestCleanup to run code after each test has run | |||||
| // [TestCleanup()] | |||||
| // public void MyTestCleanup() { } | |||||
| // | |||||
| #endregion | |||||
| [TestMethod] | |||||
| public void TestMethod1() | |||||
| { | |||||
| using (DocX document = DocX.Load(@"C:\Users\cathal\Documents\Visual Studio 2010\Projects\DocX\UnitTests\documents\simple.docx")) | |||||
| { | |||||
| Debug.Assert(document.Paragraphs.Count() == 1); | |||||
| Paragraph p = document.Paragraphs[0]; | |||||
| Debug.Assert(p.Text == "Paragraph 1"); | |||||
| Debug.Assert(p.Pictures.Count == 1); | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| <?xml version="1.0" encoding="utf-8"?> | |||||
| <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||||
| <PropertyGroup> | |||||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||||
| <ProductVersion> | |||||
| </ProductVersion> | |||||
| <SchemaVersion>2.0</SchemaVersion> | |||||
| <ProjectGuid>{3EA73F1C-9E0B-4ED5-B04B-6C043D14D1AA}</ProjectGuid> | |||||
| <OutputType>Library</OutputType> | |||||
| <AppDesignerFolder>Properties</AppDesignerFolder> | |||||
| <RootNamespace>UnitTests</RootNamespace> | |||||
| <AssemblyName>UnitTests</AssemblyName> | |||||
| <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | |||||
| <FileAlignment>512</FileAlignment> | |||||
| <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | |||||
| <SccProjectName>SAK</SccProjectName> | |||||
| <SccLocalPath>SAK</SccLocalPath> | |||||
| <SccAuxPath>SAK</SccAuxPath> | |||||
| <SccProvider>SAK</SccProvider> | |||||
| </PropertyGroup> | |||||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||||
| <DebugSymbols>true</DebugSymbols> | |||||
| <DebugType>full</DebugType> | |||||
| <Optimize>false</Optimize> | |||||
| <OutputPath>bin\Debug\</OutputPath> | |||||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | |||||
| <ErrorReport>prompt</ErrorReport> | |||||
| <WarningLevel>4</WarningLevel> | |||||
| </PropertyGroup> | |||||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||||
| <DebugType>pdbonly</DebugType> | |||||
| <Optimize>true</Optimize> | |||||
| <OutputPath>bin\Release\</OutputPath> | |||||
| <DefineConstants>TRACE</DefineConstants> | |||||
| <ErrorReport>prompt</ErrorReport> | |||||
| <WarningLevel>4</WarningLevel> | |||||
| </PropertyGroup> | |||||
| <ItemGroup> | |||||
| <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |||||
| <Reference Include="System" /> | |||||
| <Reference Include="System.Core"> | |||||
| <RequiredTargetFramework>3.5</RequiredTargetFramework> | |||||
| </Reference> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> | |||||
| <Visible>False</Visible> | |||||
| </CodeAnalysisDependentAssemblyPaths> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <Compile Include="Properties\AssemblyInfo.cs" /> | |||||
| <Compile Include="UnitTest1.cs" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <ProjectReference Include="..\DocX\DocX.csproj"> | |||||
| <Project>{E863D072-AA8B-4108-B5F1-785241B37F67}</Project> | |||||
| <Name>DocX</Name> | |||||
| </ProjectReference> | |||||
| </ItemGroup> | |||||
| <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | |||||
| <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |||||
| Other similar extension points exist, see Microsoft.Common.targets. | |||||
| <Target Name="BeforeBuild"> | |||||
| </Target> | |||||
| <Target Name="AfterBuild"> | |||||
| </Target> | |||||
| --> | |||||
| </Project> |
| "" | |||||
| { | |||||
| "FILE_VERSION" = "9237" | |||||
| "ENLISTMENT_CHOICE" = "NEVER" | |||||
| "PROJECT_FILE_RELATIVE_PATH" = "" | |||||
| "NUMBER_OF_EXCLUDED_FILES" = "0" | |||||
| "ORIGINAL_PROJECT_FILE_PATH" = "" | |||||
| "NUMBER_OF_NESTED_PROJECTS" = "0" | |||||
| "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" | |||||
| } |