Procházet zdrojové kódy

Fix Paragraph runs bag.

Start to develop chart functionality.
master
DragonFire_cp před 14 roky
rodič
revize
e37bcfe010
3 změnil soubory, kde provedl 53 přidání a 2 odebrání
  1. 36
    0
      DocX/DocX.cs
  2. 3
    1
      DocX/Paragraph.cs
  3. 14
    1
      Examples/Program.cs

+ 36
- 0
DocX/DocX.cs Zobrazit soubor

@@ -2844,6 +2844,42 @@ namespace Novacode
return p;
}
public void InsertChartInTheDevelopment()
{
// Magic
String chartXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><c:chartSpace xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"><c:date1904 val=\"0\"/><c:lang val=\"ru-RU\"/><c:roundedCorners val=\"0\"/><mc:AlternateContent xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"><mc:Choice Requires=\"c14\" xmlns:c14=\"http://schemas.microsoft.com/office/drawing/2007/8/2/chart\"><c14:style val=\"102\"/></mc:Choice><mc:Fallback><c:style val=\"2\"/></mc:Fallback></mc:AlternateContent><c:chart><c:autoTitleDeleted val=\"0\"/><c:plotArea><c:layout/><c:barChart><c:barDir val=\"col\"/><c:grouping val=\"clustered\"/><c:varyColors val=\"0\"/><c:ser><c:idx val=\"0\"/><c:order val=\"0\"/><c:tx><c:strRef><c:f>Лист1!$B$1</c:f><c:strCache><c:ptCount val=\"1\"/><c:pt idx=\"0\"><c:v>Ряд 1</c:v></c:pt></c:strCache></c:strRef></c:tx><c:invertIfNegative val=\"0\"/><c:cat><c:strRef><c:f>Лист1!$A$2:$A$5</c:f><c:strCache><c:ptCount val=\"4\"/><c:pt idx=\"0\"><c:v>Категория 1</c:v></c:pt><c:pt idx=\"1\"><c:v>Категория 2</c:v></c:pt><c:pt idx=\"2\"><c:v>Категория 3</c:v></c:pt><c:pt idx=\"3\"><c:v>Категория 4</c:v></c:pt></c:strCache></c:strRef></c:cat><c:val><c:numRef><c:f>Лист1!$B$2:$B$5</c:f><c:numCache><c:formatCode>Основной</c:formatCode><c:ptCount val=\"4\"/><c:pt idx=\"0\"><c:v>4.3</c:v></c:pt><c:pt idx=\"1\"><c:v>2.5</c:v></c:pt><c:pt idx=\"2\"><c:v>3.5</c:v></c:pt><c:pt idx=\"3\"><c:v>4.5</c:v></c:pt></c:numCache></c:numRef></c:val></c:ser><c:ser><c:idx val=\"1\"/><c:order val=\"1\"/><c:tx><c:strRef><c:f>Лист1!$C$1</c:f><c:strCache><c:ptCount val=\"1\"/><c:pt idx=\"0\"><c:v>Ряд 2</c:v></c:pt></c:strCache></c:strRef></c:tx><c:invertIfNegative val=\"0\"/><c:cat><c:strRef><c:f>Лист1!$A$2:$A$5</c:f><c:strCache><c:ptCount val=\"4\"/><c:pt idx=\"0\"><c:v>Категория 1</c:v></c:pt><c:pt idx=\"1\"><c:v>Категория 2</c:v></c:pt><c:pt idx=\"2\"><c:v>Категория 3</c:v></c:pt><c:pt idx=\"3\"><c:v>Категория 4</c:v></c:pt></c:strCache></c:strRef></c:cat><c:val><c:numRef><c:f>Лист1!$C$2:$C$5</c:f><c:numCache><c:formatCode>Основной</c:formatCode><c:ptCount val=\"4\"/><c:pt idx=\"0\"><c:v>2.4</c:v></c:pt><c:pt idx=\"1\"><c:v>4.4000000000000004</c:v></c:pt><c:pt idx=\"2\"><c:v>1.8</c:v></c:pt><c:pt idx=\"3\"><c:v>2.8</c:v></c:pt></c:numCache></c:numRef></c:val></c:ser><c:ser><c:idx val=\"2\"/><c:order val=\"2\"/><c:tx><c:strRef><c:f>Лист1!$D$1</c:f><c:strCache><c:ptCount val=\"1\"/><c:pt idx=\"0\"><c:v>Ряд 3</c:v></c:pt></c:strCache></c:strRef></c:tx><c:invertIfNegative val=\"0\"/><c:cat><c:strRef><c:f>Лист1!$A$2:$A$5</c:f><c:strCache><c:ptCount val=\"4\"/><c:pt idx=\"0\"><c:v>Категория 1</c:v></c:pt><c:pt idx=\"1\"><c:v>Категория 2</c:v></c:pt><c:pt idx=\"2\"><c:v>Категория 3</c:v></c:pt><c:pt idx=\"3\"><c:v>Категория 4</c:v></c:pt></c:strCache></c:strRef></c:cat><c:val><c:numRef><c:f>Лист1!$D$2:$D$5</c:f><c:numCache><c:formatCode>Основной</c:formatCode><c:ptCount val=\"4\"/><c:pt idx=\"0\"><c:v>2</c:v></c:pt><c:pt idx=\"1\"><c:v>2</c:v></c:pt><c:pt idx=\"2\"><c:v>3</c:v></c:pt><c:pt idx=\"3\"><c:v>5</c:v></c:pt></c:numCache></c:numRef></c:val></c:ser><c:dLbls><c:showLegendKey val=\"0\"/><c:showVal val=\"0\"/><c:showCatName val=\"0\"/><c:showSerName val=\"0\"/><c:showPercent val=\"0\"/><c:showBubbleSize val=\"0\"/></c:dLbls><c:gapWidth val=\"150\"/><c:axId val=\"148921728\"/><c:axId val=\"154227840\"/></c:barChart><c:catAx><c:axId val=\"148921728\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"0\"/><c:axPos val=\"b\"/><c:majorTickMark val=\"out\"/><c:minorTickMark val=\"none\"/><c:tickLblPos val=\"nextTo\"/><c:crossAx val=\"154227840\"/><c:crosses val=\"autoZero\"/><c:auto val=\"1\"/><c:lblAlgn val=\"ctr\"/><c:lblOffset val=\"100\"/><c:noMultiLvlLbl val=\"0\"/></c:catAx><c:valAx><c:axId val=\"154227840\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"0\"/><c:axPos val=\"l\"/><c:majorGridlines/><c:numFmt formatCode=\"Основной\" sourceLinked=\"1\"/><c:majorTickMark val=\"out\"/><c:minorTickMark val=\"none\"/><c:tickLblPos val=\"nextTo\"/><c:crossAx val=\"148921728\"/><c:crosses val=\"autoZero\"/><c:crossBetween val=\"between\"/></c:valAx></c:plotArea><c:legend><c:legendPos val=\"r\"/><c:overlay val=\"0\"/></c:legend><c:plotVisOnly val=\"1\"/><c:dispBlanksAs val=\"gap\"/><c:showDLblsOverMax val=\"0\"/></c:chart></c:chartSpace>";
// Create a new chart part uri.
String chartPartUriPath = String.Empty;
Int32 chartIndex = 1;
do
{
chartPartUriPath = String.Format
(
"/word/charts/chart{0}.xml",
chartIndex
);
} while (package.PartExists(new Uri(chartPartUriPath, UriKind.Relative)));
// Create chart part.
PackagePart chart = package.CreatePart(new Uri(chartPartUriPath, UriKind.Relative), "application/vnd.openxmlformats-officedocument.drawingml.chart+xml");
// Create a new chart relationship
PackageRelationship rel = mainPart.CreateRelationship(chart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", "rId5");
// Open a Stream to the newly created Image part.
using (Stream stream = chart.GetStream(FileMode.Create, FileAccess.Write))
{
byte[] byteArray = Encoding.UTF8.GetBytes(chartXml);
stream.Write(byteArray, 0, byteArray.Length);
}
Paragraph p = InsertParagraph();
p.Xml.Add(XElement.Parse("<w:r xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\"><w:rPr><w:noProof/></w:rPr><w:drawing><wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\"><wp:extent cx=\"5486400\" cy=\"3200400\"/><wp:effectExtent l=\"0\" t=\"0\" r=\"19050\" b=\"19050\"/><wp:docPr id=\"1\" name=\"123\"/><wp:cNvGraphicFramePr/><a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/chart\"><c:chart xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:id=\"rId5\"/></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>"));
}
#region IDisposable Members
/// <summary>

+ 3
- 1
DocX/Paragraph.cs Zobrazit soubor

@@ -165,7 +165,7 @@ namespace Novacode
this.startIndex = startIndex;
this.endIndex = startIndex + GetElementTextLength(xml);
RebuildDocProperties();
RebuildDocProperties();
#region It's possible that a Paragraph may have pStyle references
// Check if this Paragraph references any pStyle elements.
@@ -200,6 +200,8 @@ namespace Novacode
}
}
#endregion
this.runs = Xml.Elements(XName.Get("r", DocX.w.NamespaceName)).ToList();
}
/// <summary>

+ 14
- 1
Examples/Program.cs Zobrazit soubor

@@ -15,6 +15,9 @@ namespace Examples
{
static void Main(string[] args)
{
// In the development...
ChartInTheDevelopment();
// Easy
Console.WriteLine("\nRunning Easy Examples");
HelloWorld();
@@ -33,12 +36,22 @@ namespace Examples
// Advanced
Console.WriteLine("\nRunning Advanced Examples");
ProgrammaticallyManipulateImbeddedImage();
ReplaceTextParallel();
ReplaceTextParallel();
Console.WriteLine("\nPress any key to exit.");
Console.ReadKey();
}
private static void ChartInTheDevelopment()
{
using (DocX document = DocX.Create(@"docs\Chart.docx"))
{
document.InsertParagraph("Красивая диаграмма").FontSize(20);
document.InsertChartInTheDevelopment();
document.Save();
}
}
/// <summary>
/// Create a document with two equations.
/// </summary>

Načítá se…
Zrušit
Uložit