我用com调用了word程序,然后动态的改动了文档。
可是,我想直接得到改动后的文档的byte[].不希望存储到磁盘上。各位兄弟有办法吗?

解决方案 »

  1.   

    static void Main(string[] args)
    {
    //Create a word object that we can manipulate
    Word.Application Word_app=new Word.Application();
    Word.Document Word_doc=new Word.Document();

    //Make Word Application Form visible.
    Word_app.Visible=true; Word.Documents docs=Word_app.Documents;

    //open a exist word document.
    object template="c:\\temp\\test.dot";
    object missing=Type.Missing;
    Word_doc=docs.Add(ref template,ref missing,ref missing,ref missing); // define the selection object, find and  replace text
    Word.Window myWindow = Word_app.ActiveWindow;
    Word.Selection mySelection = myWindow.Selection; 
    Word.Find myFind = mySelection.Find;
    object findText = "alow";
    object replaceText ="allow"; // Find "alow" and replace with "allow"

    myFind.Execute(ref findText,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref replaceText,ref missing,ref missing,ref missing,ref missing,ref missing);

                                //count how many words in your document.
    int intEnd=Word_doc.Words.Count;    //Define a range to be read to byte[].
    object start=0;
    object end=intEnd;
    Word.Range range=Word_doc.Range(ref start,ref end);
    string strText=range.Text;
    byte[] buffer=new byte[10000];
    //Encoding.ASCII.GetBytes(strText,0,.Length,buffer,0);
    Encoding.ASCII.GetBytes(strText,0,strText.Length,buffer,0);
    }