Aspose.Words使用教程之(如何使用ChartDataLabel),(如何重新命名合併欄位)
使用ChartDataLabel
你可以規定單個圖表系列的資料標籤的格式,像顯現/隱藏圖例、種類名字、SeriesName
、值等等。
ChartDataLabelCollection dataLabelCollection = series0.DataLabels;
// Add data label to the first and second point of the first series.
ChartDataLabel chartDataLabel00 = dataLabelCollection.Add(0);
ChartDataLabel chartDataLabel01 = dataLabelCollection.Add(1);
// Set properties.
chartDataLabel00.ShowLegendKey = true;
// By default, when you add data labels to the data points in a pie chart, leader lines are displayed for data labels that are
// positioned far outside the end of data points. Leader lines create a visual connection between a data label and its
// corresponding data point.
chartDataLabel00.ShowLeaderLines = true;
chartDataLabel00.ShowCategoryName = false;
chartDataLabel00.ShowPercentage = false;
chartDataLabel00.ShowSeriesName = true;
chartDataLabel00.ShowValue = true;
chartDataLabel00.Separator = "/";
chartDataLabel01.ShowValue = true;
結果如下:
一個示例展示如何建立自己的合併欄位類,代表一個在微軟的Word
文件中允許您獲取或設定它合併欄位的名稱。
Example
如何在一個文件裡重新命名欄位。
using System;
using System.Text;
using System.Text.RegularExpressions;
using Aspose.Words;
using Aspose.Words.Fields;
namespace Examples
{
/// <summary>
/// Shows how to rename merge fields in a Word document.
/// </summary>
public class ExRenameMergeFields : ExBase
{
/// <summary>
/// Finds all merge fields in a Word document and changes their names.
/// </summary>
public void RenameMergeFields()
{
// Specify your document name here.
Document doc = new Document(MyDir + "RenameMergeFields.doc");
// Select all field start nodes so we can find the merge fields.
NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart fieldStart in fieldStarts)
{
if (fieldStart.FieldType.Equals(FieldType.FieldMergeField))
{
MergeField mergeField = new MergeField(fieldStart);
mergeField.Name = mergeField.Name + "_Renamed";
}
}
doc.Save(MyDir + "RenameMergeFields Out.doc");
}
}
/// <summary>
/// Represents a facade object for a merge field in a Microsoft Word document.
/// </summary>
internal class MergeField
{
internal MergeField(FieldStart fieldStart)
{
if (fieldStart.Equals(null))
throw new ArgumentNullException("fieldStart");
if (!fieldStart.FieldType.Equals(FieldType.FieldMergeField))
throw new ArgumentException("Field start type must be FieldMergeField.");
mFieldStart = fieldStart;
// Find the field separator node.
mFieldSeparator = fieldStart.GetField().Separator;
if (mFieldSeparator == null)
throw new InvalidOperationException("Cannot find field separator.");
mFieldEnd = fieldStart.GetField().End;
}
/// <summary>
/// Gets or sets the name of the merge field.
/// </summary>
internal string Name
{
get
{
return ((FieldStart)mFieldStart).GetField().Result.Replace("«", "").Replace("»", "");
}
set
{
// Merge field name is stored in the field result which is a Run
// node between field separator and field end.
Run fieldResult = (Run)mFieldSeparator.NextSibling;
fieldResult.Text = string.Format("«{0}»", value);
// But sometimes the field result can consist of more than one run, delete these runs.
RemoveSameParent(fieldResult.NextSibling, mFieldEnd);
UpdateFieldCode(value);
}
}
private void UpdateFieldCode(string fieldName)
{
// Field code is stored in a Run node between field start and field separator.
Run fieldCode = (Run)mFieldStart.NextSibling;
Match match = gRegex.Match(((FieldStart)mFieldStart).GetField().GetFieldCode());
string newFieldCode = string.Format(" {0}{1} ", match.Groups["start"].Value, fieldName);
fieldCode.Text = newFieldCode;
// But sometimes the field code can consist of more than one run, delete these runs.
RemoveSameParent(fieldCode.NextSibling, mFieldSeparator);
}
/// <summary>
/// Removes nodes from start up to but not including the end node.
/// Start and end are assumed to have the same parent.
/// </summary>
private static void RemoveSameParent(Node startNode, Node endNode)
{
if ((endNode != null) && (startNode.ParentNode != endNode.ParentNode))
throw new ArgumentException("Start and end nodes are expected to have the same parent.");
Node curChild = startNode;
while ((curChild != null) && (curChild != endNode))
{
Node nextChild = curChild.NextSibling;
curChild.Remove();
curChild = nextChild;
}
}
private readonly Node mFieldStart;
private readonly Node mFieldSeparator;
private readonly Node mFieldEnd;
private static readonly Regex gRegex = new Regex(@"\s*(?<start>MERGEFIELD\s|)(\s|)(?<name>\S+)\s+");
}
}
相關文章
- Aspose.Words使用教程之如何寫入純文字(TXT)檔案,表的合併與拆分
- Aspose.Words使用教程之如何操作主題屬性,如何在文件中新增水印
- Aspose.Words使用教程之插入文件元素(一)
- Aspose.Words使用教程之插入文件元素(二)
- Aspose.Words使用教程之插入文件元素(三)
- 如何使用Wondershare UniConverter for Mac合併影片?Mac
- 請教一下 多欄位值如何排序?排序
- pandas中如何使用合併append函式?APP函式
- 資料處理之欄位合併
- 使用 Eloquent ORM 使用 with 模型關聯查詢,如何處理select不同模型的欄位(欄位名可能相同)ORM模型
- 使用HDR Efex Pro 2 mac版如何合併影像?Mac
- Aspose.Words使用教程之在文件中找到並替換文字
- Mac技巧分享——如何使用快捷鍵進行文欄位落定位Mac
- 如何使用odoo的compute方法,自動計算odoo欄位Odoo
- Aspose.Words使用教程之從零在word裡建立OOXML圖表XML
- DB 合併多個欄位的模糊檢索
- 【java】Aspose.Words 合併單元格2種情況(橫向合併,縱向合併)Java
- abc欄位數的使用
- 使用hibernate校驗欄位
- mongodb如何改_id欄位?MongoDB
- 教大家如何在html中使用特殊字型HTML
- Aspose.Words實現郵件合併功能和列印
- 影片合併分割軟體如何合併影片
- Drupal 如何得到欄位的值?
- 今日教學:RestTemplate 結合 Ribbon 使用REST
- SAP不同的產品是如何支援使用者建立自定義欄位的
- 精通併發與 Netty (一)如何使用Netty
- 如何使用Python曲線擬合Python
- MySQL 中 JSON 欄位的使用技巧MySqlJSON
- MySQL中JSON欄位的使用技巧MySqlJSON
- 如何使用BFC清除CSS浮動以及解決margin合併的問題CSS
- git 入門教程之衝突合併Git
- git 入門教程之變基合併Git
- Pandas高階教程之:Dataframe的合併
- python字典合併的使用注意Python
- Linux使用ffmpeg合併視訊Linux
- 如何合併兩個TensorFlow模型模型
- Git - 如何取消正在的合併Git