小弟想作个自动判分系统,针对word或excel操作的,比如word,要对格式操作是否正确进行自动判断。现在想到的方法有两个:
1、将word转换为xml。
2、将word转换为二进制。
通过和标准的word的xml或二进制代码的比较来判断是否完成。
现在有几个问题:
1、word转换为以上两种格式是否是唯一的;
2、.net中对word的转换操作如何进行。
希望各位高手赐教,多谢!~~~

解决方案 »

  1.   

    SqlConnection con = new SqlConnection("Server=.;uid=sa;pwd=sa;Database=tksqldb_train");
    SqlDataAdapter da = new SqlDataAdapter("select st_nr from stid1 where st_id=328", con);
    SqlCommandBuilder MyCB = new SqlCommandBuilder(da);
    DataSet ds = new DataSet("st_nr");
    byte[] MyData= new byte[0];

    da.Fill(ds, "stid1");
    DataRow myRow;
    myRow=ds.Tables["stid1"].Rows[0];
               
    MyData =  (byte[])myRow["st_nr"];
    int ArraySize = new int();
    ArraySize = MyData.GetUpperBound(0);  FileStream fs = new FileStream(@"c:\test1.doc", FileMode.OpenOrCreate, FileAccess.Write);
    fs.Write(MyData, 0,ArraySize);
    fs.Close();
    con.Close();
    Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();  // 指定源文件和目标文件
    object Source=@"c:\test1.doc";
    object Target=@"c:\test1.html";
    object Unknown =Type.Missing;
    // 打开要转换的Word文件
    newApp.Documents.Open(ref Source,ref Unknown, 
    ref Unknown,ref Unknown,ref Unknown, 
    ref Unknown,ref Unknown,ref Unknown, 
    ref Unknown,ref Unknown,ref Unknown, 
    ref Unknown,ref Unknown,ref Unknown,ref Unknown,ref Unknown); // 指定文档的类型
    object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML   ; //改变文档类型
    newApp.ActiveDocument.SaveAs(ref Target,ref format, 
    ref Unknown,ref Unknown,ref Unknown, 
    ref Unknown,ref Unknown,ref Unknown, 
    ref Unknown,ref Unknown,ref Unknown,ref Unknown,ref Unknown,ref Unknown,ref Unknown,ref Unknown);                     //关闭word实例
    newApp.Quit(ref Unknown,ref Unknown,ref Unknown);
    MessageBox.Show("转换成html成功!");
      

  2.   

    把那个WDSaveFormat后面的换成xml就保存成xml了