private XTextSubDocumentElement CreateNewSubDocument(XTextDocument document, string xml) { XTextSubDocumentElement doc = new XTextSubDocumentElement(); doc.OwnerDocument = document; doc.DocumentInfo.Author = System.Environment.UserName; doc.DocumentInfo.Title = DateTime.Now.ToString("病程记录yyyy年MM月dd日 HH时mm分ss秒"); doc.ID = doc.Title; doc.LoadDocumentFromString(xml, "xml"); //doc.SetInnerTextFast(xml); // 新文档不启用权限 doc.EnablePermission = DCBooleanValue.False; // 新文档是不只读的 doc.ContentReadonly = ContentReadonlyState.False; // 打印时背景透明 doc.Style.PrintBackColor = Color.Transparent; //// 设置新的文件名 string fileName = doc.DocumentInfo.Title + ".xml"; doc.FileName = fileName; return(doc); }
public WriterDocument(XTextDocument xTextDocument, XComponentContext xContext = null, XMultiComponentFactory xMcFactory = null) { this.xContext = xContext; this.xMcFactory = xMcFactory; doc = xTextDocument; }
public WriterDocument(XTextDocument xTextDocument, XComponentContext xContext = null, XMultiComponentFactory xMcFactory = null) { this.xContext = xContext; this.xMcFactory = xMcFactory; doc = xTextDocument; }
static void Main(string[] args) { InitOpenOfficeEnvironment(); XMultiServiceFactory multiServiceFactory = Connect(); XComponent xComponent = null; string docFileName = @"C:\test3.doc"; try { XComponentLoader componentLoader = (XComponentLoader)multiServiceFactory .createInstance("com.sun.star.frame.Desktop"); //set the property PropertyValue[] propertyValue = new PropertyValue[1]; PropertyValue aProperty = new PropertyValue(); aProperty.Name = "Hidden"; aProperty.Value = new uno.Any(false); propertyValue[0] = aProperty; xComponent = componentLoader .loadComponentFromURL(PathConverter(docFileName), "_blank", 0, propertyValue); XTextDocument xTextDocument = ((XTextDocument)xComponent); XEnumerationAccess xEnumerationAccess = (XEnumerationAccess)xTextDocument.getText(); XEnumeration xParagraphEnumeration = xEnumerationAccess.createEnumeration(); while (xParagraphEnumeration.hasMoreElements()) { uno.Any element = xParagraphEnumeration.nextElement(); XServiceInfo xinfo = (XServiceInfo)element.Value; if (xinfo.supportsService("com.sun.star.text.TextTable")) { Console.WriteLine("Found Table!"); XTextTable xTextTable = (XTextTable)element.Value; String[] cellNames = xTextTable.getCellNames(); for (int i = 0; i < cellNames.Length; i++) { XCell xCell = xTextTable.getCellByName(cellNames[i]); XText xTextCell = (XText)xCell; String strText = xTextCell.getString(); Console.WriteLine(strText); } } else { XTextContent xTextElement = (XTextContent)element.Value; XEnumerationAccess xParaEnumerationAccess = (XEnumerationAccess)xTextElement; // create another enumeration to get all text portions of //the paragraph XEnumeration xTextPortionEnum = xParaEnumerationAccess.createEnumeration(); //step 3 Through the Text portions Enumeration, get interface //to each individual text portion while (xTextPortionEnum.hasMoreElements()) { XTextRange xTextPortion = (XTextRange)xTextPortionEnum.nextElement().Value; Console.Write(xTextPortion.getString()); } } } } catch (unoidl.com.sun.star.uno.Exception exp1) { Console.WriteLine(exp1.Message); Console.WriteLine(exp1.StackTrace); } catch (System.Exception exp2) { Console.WriteLine(exp2.Message); Console.WriteLine(exp2.StackTrace); } finally { xComponent.dispose(); xComponent = null; } Console.WriteLine("Done."); Console.ReadLine(); }