本文整理匯總了C#中Text.GetAttributes方法的典型用法代碼示例。如果您正苦於以下問題:C# Text.GetAttributes方法的具體用法?C# Text.GetAttributes怎麽用?C# Text.GetAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Text
的用法示例。
在下文中一共展示了Text.GetAttributes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteStringTest
public void WriteStringTest()
{
using (var memStream = new MemoryStream())
using (OpenXmlPartWriter target = new OpenXmlPartWriter(memStream))
{
string text = "abc";
target.WriteStartDocument();
target.WriteStartElement(new Run());
target.WriteStartElement(new Text());
target.WriteString(text);
target.WriteEndElement();
var textElement = new Text();
textElement.Space = new EnumValue<SpaceProcessingModeValues>();
textElement.Space.Value = SpaceProcessingModeValues.Preserve;
target.WriteStartElement(new Text(), textElement.GetAttributes());
target.WriteString(text);
target.WriteString(text);
target.WriteEndElement();
var run = new Run(new Text("111"), new Text("222"));
using (var reader = OpenXmlReader.Create(run))
{
reader.Read();
reader.Read();
target.WriteStartElement(reader);
target.WriteString(reader.GetText());
reader.Read();
target.WriteEndElement();
reader.Read();
target.WriteStartElement(reader, textElement.GetAttributes());
target.WriteString(reader.GetText());
target.WriteString(text);
reader.Read();
target.WriteEndElement();
reader.Close();
}
target.Close();
}
}
示例2: WriteStringExceptionTest6
public void WriteStringExceptionTest6()
{
using (var memStream = new MemoryStream())
using (OpenXmlPartWriter target = new OpenXmlPartWriter(memStream))
{
string text = "abc";
target.WriteStartDocument();
target.WriteStartElement(new Run());
var textElement = new Text();
textElement.Space = SpaceProcessingModeValues.Preserve;
target.WriteStartElement(new RunProperties(), textElement.GetAttributes());
target.WriteEndElement();
target.Close();
Assert.Throws<System.InvalidOperationException>(() =>
{
target.WriteString(text); // exception
});
}
}