操作多行文本, 导出多行文本的内容到word2007
int co;
string[] ct;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
TypedValue[] acval = new TypedValue[2];
acval.SetValue(new TypedValue((int)DxfCode.LayerName, "校审"), 0);
acval.SetValue(new TypedValue((int)DxfCode.Start, "MTEXT"), 1);
using (doc.LockDocument())
{
using (Transaction tran = db.TransactionManager.StartTransaction())
{
wordapp = new Msword.ApplicationClass();
wordapp.DisplayAlerts = Msword.WdAlertLevel.wdAlertsNone;
wordapp.Visible = true;
object missing = System.Reflection.Missing.Value;
string path = "D:\\model\\model.doc";
object templatename = path;
object dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\桌面.doc";
// worddoc = wordapp.Documents.Add(ref templatename, ref missing, ref missing, ref missing);
// path = Environment.CurrentDirectory + "\\demo.doc";
object format = Msword.WdSaveFormat.wdFormatDocument;
worddoc = wordapp.Documents.Add(ref templatename, ref missing, ref missing, ref missing);
SelectionFilter Self = new SelectionFilter(acval);
// PromptSelectionOptions pso = new PromptSelectionOptions();
PromptSelectionResult PR = ed.GetSelection(Self);
if (PR.Status == PromptStatus.OK)
{
SelectionSet aset = PR.Value;
co = aset.Count;
ObjectId[] oid = aset.GetObjectIds();
ct = new string[co];
for (int i = 0; i < co; i++)
{
MText mt = (MText)tran.GetObject(oid[i], OpenMode.ForRead);
ct[i] = mt.Text;
worddoc.Paragraphs.Last.Range.Text += ct[i];
}
}
worddoc.SaveAs(ref dir, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
//}
tran.Commit();
}
}
}