本文整理汇总了C#中NPOI.XWPF.UserModel.XWPFDocument类的典型用法代码示例。如果您正苦于以下问题:C# XWPFDocument类的具体用法?C# XWPFDocument怎么用?C# XWPFDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XWPFDocument类属于NPOI.XWPF.UserModel命名空间,在下文中一共展示了XWPFDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
XWPFDocument doc = new XWPFDocument();
XWPFParagraph para= doc.CreateParagraph();
XWPFRun r0 = para.CreateRun();
r0.SetText("Title1");
para.BorderTop = Borders.THICK;
para.FillBackgroundColor = "EEEEEE";
para.FillPattern = NPOI.OpenXmlFormats.Wordprocessing.ST_Shd.diagStripe;
XWPFTable table = doc.CreateTable(3, 3);
table.GetRow(1).GetCell(1).SetText("EXAMPLE OF TABLE");
XWPFTableCell c1 = table.GetRow(0).GetCell(0);
XWPFParagraph p1 = c1.AddParagraph(); //don't use doc.CreateParagraph
XWPFRun r1 = p1.CreateRun();
r1.SetText("The quick brown fox");
r1.SetBold(true);
r1.FontFamily = "Courier";
r1.SetUnderline(UnderlinePatterns.DotDotDash);
r1.SetTextPosition(100);
c1.SetColor("FF0000");
table.GetRow(2).GetCell(2).SetText("only text");
FileStream out1 = new FileStream("simpleTable.docx", FileMode.Create);
doc.Write(out1);
out1.Close();
}
示例2: Main
static void Main(string[] args)
{
XWPFDocument doc = new XWPFDocument(new FileStream("data/Extract Images from Word Document.doc",FileMode.Open));
IList<XWPFPictureData> pics = doc.AllPictures;
foreach (XWPFPictureData pic in pics)
{
FileStream outputStream = new FileStream("data/NPOI_" + pic.FileName,FileMode.OpenOrCreate);
byte[] picData= pic.Data;
outputStream.Write(picData, 0, picData.Length);
outputStream.Close();
}
}
示例3: WriteOutAndReadBack
public static XWPFDocument WriteOutAndReadBack(XWPFDocument doc)
{
MemoryStream baos = new MemoryStream(4096);
doc.Write(baos);
MemoryStream bais = new MemoryStream(baos.ToArray());
return new XWPFDocument(bais);
}
示例4: SetUp
public void SetUp()
{
XWPFDocument doc = new XWPFDocument();
p = doc.CreateParagraph();
this.ctRun = new CT_R();
}
示例5: FindTable
public DataTable FindTable(string filepath)
{
try
{
using (FileStream stream = File.OpenRead(filepath))
{
XWPFDocument doc = new XWPFDocument(stream);
foreach (XWPFTable table in doc.Tables)
{
if (Row2Cell1Contains(table, @"Run") && Row1Cell1Contains(table, @"General"))
{
return WordTableToDataTable.GetDataTable(table);
}
}
return null;
}
}
catch (AccessViolationException avex)
{
throw new AccessViolationException(string.Format("You do not have permission to access the file " + avex.Message));
}
catch (System.IO.IOException ioex)
{
throw new System.IO.IOException(ioex.Message.Replace("\'", "<br />") + "<br /><br />Someone has file open and it is therefore locked.");
}
}
示例6: LoadFile
public void LoadFile(String path)
{
using(var file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
_document = new XWPFDocument(file);
}
}
示例7: Main
static void Main(string[] args)
{
// Create a new document from scratch
XWPFDocument doc = new XWPFDocument();
XWPFTable table = doc.CreateTable(3, 3);
table.GetRow(1).GetCell(1).SetText("EXAMPLE OF TABLE");
XWPFTableCell c1 = table.GetRow(0).GetCell(0);
XWPFParagraph p1 = c1.AddParagraph(); //don't use doc.CreateParagraph
XWPFRun r1 = p1.CreateRun();
r1.SetText("This is test table contents");
r1.SetBold(true);
r1.FontFamily = "Courier";
r1.SetUnderline(UnderlinePatterns.DotDotDash);
r1.SetTextPosition(100);
c1.SetColor("FF0000");
table.GetRow(2).GetCell(2).SetText("only text");
FileStream out1 = new FileStream("Format Table in Document.docx", FileMode.Create);
doc.Write(out1);
out1.Close();
}
示例8: TestSetGetVertAlignment
public void TestSetGetVertAlignment()
{
// instantiate the following classes so they'll Get picked up by
// the XmlBean process and Added to the jar file. they are required
// for the following XWPFTableCell methods.
CT_Shd ctShd = new CT_Shd();
Assert.IsNotNull(ctShd);
CT_VerticalJc ctVjc = new CT_VerticalJc();
Assert.IsNotNull(ctVjc);
ST_Shd stShd = ST_Shd.nil;
Assert.IsNotNull(stShd);
ST_VerticalJc stVjc = ST_VerticalJc.top;
Assert.IsNotNull(stVjc);
// create a table
XWPFDocument doc = new XWPFDocument();
CT_Tbl ctTable = new CT_Tbl();
XWPFTable table = new XWPFTable(ctTable, doc);
// table has a single row by default; grab it
XWPFTableRow tr = table.GetRow(0);
Assert.IsNotNull(tr);
// row has a single cell by default; grab it
XWPFTableCell cell = tr.GetCell(0);
cell.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.BOTH);
XWPFTableCell.XWPFVertAlign al = cell.GetVerticalAlignment();
Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al);
}
示例9: TestWord
public void TestWord()
{
POIXMLDocument doc = new XWPFDocument(
POIDataSamples.GetDocumentInstance().OpenResourceAsStream("WordWithAttachments.docx")
);
Test(doc, 5);
}
示例10: TestCreateRow
public void TestCreateRow()
{
XWPFDocument doc = new XWPFDocument();
CT_Tbl table = new CT_Tbl();
CT_Row r1 = table.AddNewTr();
r1.AddNewTc().AddNewP();
r1.AddNewTc().AddNewP();
CT_Row r2 = table.AddNewTr();
r2.AddNewTc().AddNewP();
r2.AddNewTc().AddNewP();
CT_Row r3 = table.AddNewTr();
r3.AddNewTc().AddNewP();
r3.AddNewTc().AddNewP();
XWPFTable xtab = new XWPFTable(table, doc);
Assert.AreEqual(3, xtab.GetNumberOfRows());
Assert.IsNotNull(xtab.GetRow(2));
//add a new row
xtab.CreateRow();
Assert.AreEqual(4, xtab.GetNumberOfRows());
//check number of cols
Assert.AreEqual(2, table.GetTrArray(0).SizeOfTcArray());
//check creation of first row
xtab = new XWPFTable(new CT_Tbl(), doc);
Assert.AreEqual(1, xtab.GetCTTbl().GetTrArray(0).SizeOfTcArray());
}
示例11: XWPFHeader
public XWPFHeader(XWPFDocument doc, CT_HdrFtr hdrFtr)
: base(doc, hdrFtr)
{
/*
XmlCursor cursor = headerFooter.NewCursor();
cursor.SelectPath("./*");
while (cursor.ToNextSelection()) {
XmlObject o = cursor.Object;
if (o is CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
paragraphs.Add(p);
}
if (o is CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
tables.Add(t);
}
}
cursor.Dispose();*/
foreach (object o in hdrFtr.Items)
{
if (o is CT_P)
{
XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
paragraphs.Add(p);
}
if (o is CT_Tbl)
{
XWPFTable t = new XWPFTable((CT_Tbl)o, this);
tables.Add(t);
}
}
}
示例12: Bug55802
public void Bug55802()
{
String blabla =
"Bir, iki, \u00fc\u00e7, d\u00f6rt, be\u015f,\n" +
"\nalt\u0131, yedi, sekiz, dokuz, on.\n" +
"\nK\u0131rm\u0131z\u0131 don,\n" +
"\ngel bizim bah\u00e7eye kon,\n" +
"\nsar\u0131 limon";
XWPFDocument doc = new XWPFDocument();
XWPFRun run = doc.CreateParagraph().CreateRun();
foreach (String str in blabla.Split("\n".ToCharArray()))
{
run.SetText(str);
run.AddBreak();
}
run.FontFamily = (/*setter*/"Times New Roman");
run.FontSize = (/*setter*/20);
Assert.AreEqual(run.FontFamily, "Times New Roman");
Assert.AreEqual(run.GetFontFamily(FontCharRange.CS), "Times New Roman");
Assert.AreEqual(run.GetFontFamily(FontCharRange.EastAsia), "Times New Roman");
Assert.AreEqual(run.GetFontFamily(FontCharRange.HAnsi), "Times New Roman");
run.SetFontFamily("Arial", FontCharRange.HAnsi);
Assert.AreEqual(run.GetFontFamily(FontCharRange.HAnsi), "Arial");
}
示例13: Main
static void Main(string[] args)
{
if (args.Length != 2)
return;
string src = args[0];
string target = args[1];
RunMode mode= RunMode.Excel;
if (src.Contains(".docx"))
mode = RunMode.Word;
if (mode == RunMode.Excel)
{
Stream rfs = File.OpenRead(src);
IWorkbook workbook = new XSSFWorkbook(rfs);
rfs.Close();
using (FileStream fs = File.Create(target))
{
workbook.Write(fs);
}
}
else
{
Stream rfs = File.OpenRead(src);
XWPFDocument workbook = new XWPFDocument(rfs);
rfs.Close();
using (FileStream fs = File.Create(target))
{
workbook.Write(fs);
}
}
}
示例14: GetHyperlink
/**
* If this Hyperlink is an external reference hyperlink,
* return the object for it.
*/
public XWPFHyperlink GetHyperlink(XWPFDocument document)
{
String id = GetHyperlinkId();
if (id == null)
return null;
return document.GetHyperlinkByID(id);
}
示例15: Main
static void Main(string[] args)
{
XWPFDocument doc = new XWPFDocument();
doc.CreateParagraph();
FileStream sw = File.OpenWrite("blank.docx");
doc.Write(sw);
sw.Close();
}