【欢迎大家一起交流讨论】关于Word的自动检测修改--论文格式修正系统(毕业设计)...

我的毕业设计:论文格式修正系统,名字是自己取的,方便大家理解。

具体干啥呢?

所谓的市场价值,也就是我认为的意义:主要是现在大学论文,毕业论文,硕士论文,博士论文格式都很固定,但是广大的大学生,硕士生等就像小学生一样会犯这种格式的错误,而大学老师,博士,讲师又懒得去改这些,我的课题就出来了,论文格式修正...

这个东西的市场价值我觉得可能在学校会大一些,如果做成一个系列的产品进入高校估计还是有点市场的。

下面我还是主要讲一下具体开发需要去了解和技术要求,这个东西开发主要还是要建立在微软的office基础上,因为题目的另一个名字,word的自动检测,前面的东西我就略过了,直接讲实在的东西:

用Visual Studio写,语言C#,B/S模式,需要引入微软的COM组件,下面我先介绍一下这个东西

关于Microsoft.Office.Interop.Word类库

http://hi.baidu.com/imouse728/blog/item/c406208022f9c1d19023d925.html这个里面已经说得很清楚了

关于头部的引用就是using word;

这样我们就可以用根据这个东西参考帮助文档里面的类库说明,写一些关于word的操作说明了。

比如word的创建,word的读取,word里面段落的读取...

这些都是很简单的,网上也有很多的说明....

http://www.360doc.com/content/090510/10/64176_3440638.html

http://gzkeith.blog.163.com/blog/static/499164120069318531759/

http://www.cnblogs.com/Andmm/archive/2008/06/18/1224422.html

程序最重要的是算法,这里我的程序最关键的也就在这里了:

系统最关键部分:两篇Word文档比较(一篇是学生的论文,一篇是范文),得到一个报告。

这个比较怎么做呢?要考虑很多问题...我随便写几个

1.论文的格式好多,你怎么选择固定的格式

2.你比较得到的报告肯定是越详细越好,但是你比较的东西也会越多,摘要,关键词格式,字体大小等等

3.学生论文是很多的,肯定要考虑到批量修改,那么算法是越优化越好

。。。。

下面是我收集的一些材料和我写的一些程序,算是一个实例化的可行性分析,里面包含了一个完整的word操作代码

如果你只是需要学习点东西,那你可以直接拿去,如果你对此感兴趣或者是这方面的高手,希望能跟你交流,得到你的帮助

加QQ留言都可以。

1.我收集的资料下载

2.我写的测试程序下载

 

ExpandedBlockStart.gif 代码
using  System;
using  System.Configuration;
using  System.Data;
using  System.Linq;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.HtmlControls;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Xml.Linq;
using  System.Reflection;
using  Word;


public   partial   class  _Default : System.Web.UI.Page 
{
    
protected   void  Page_Load( object  sender, EventArgs e)
    {
        
    }
    
protected   void  Button1_Click( object  sender, EventArgs e)
    {
        
object  filename  =   " F:\\wordtest\\myword.doc " ;
        
object  oMissing  =  System.Reflection.Missing.Value;
        
object  oEndOfDoc  =   " \\endofdoc " /*  \endofdoc is a predefined bookmark  */

        
// Start Word and create a new document.
        Word._Application oWord;
        Word._Document oDoc;
        oWord 
=   new  Word.Application();
        oWord.Visible 
=   true ;
        oDoc 
=  oWord.Documents.Add( ref  oMissing,  ref  oMissing,
         
ref  oMissing,  ref  oMissing);

        
// Insert a paragraph at the beginning of the document.
        Word.Paragraph oPara1;
        oPara1 
=  oDoc.Content.Paragraphs.Add( ref  oMissing);
        oPara1.Range.Text 
=   " Heading 1 " ;
        oPara1.Range.Font.Bold 
=   1 ;
        oPara1.Format.SpaceAfter 
=   24 ;     // 24 pt spacing after paragraph.
        oPara1.Range.InsertParagraphAfter();

        
// Insert a paragraph at the end of the document.
        Word.Paragraph oPara2;
        
object  oRng  =  oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;
        oPara2 
=  oDoc.Content.Paragraphs.Add( ref  oRng);
        oPara2.Range.Text 
=   " Heading 2 " ;
        oPara2.Format.SpaceAfter 
=   6 ;
        oPara2.Range.InsertParagraphAfter();

        
// Insert another paragraph.
        Word.Paragraph oPara3;
        oRng 
=  oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;
        oPara3 
=  oDoc.Content.Paragraphs.Add( ref  oRng);
        oPara3.Range.Text 
=   " This is a sentence of normal text. Now here is a table: " ;
        oPara3.Range.Font.Bold 
=   0 ;
        oPara3.Format.SpaceAfter 
=   24 ;
        oPara3.Range.InsertParagraphAfter();

        
// Insert a 3 x 5 table, fill it with data, and make the first row
        
// bold and italic.
        Word.Table oTable;
        Word.Range wrdRng 
=  oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;
        oTable 
=  oDoc.Tables.Add(wrdRng,  3 5 ref  oMissing,  ref  oMissing);
        oTable.Range.ParagraphFormat.SpaceAfter 
=   6 ;
        
int  r, c;
        
string  strText;
        
for  (r  =   1 ; r  <=   3 ; r ++ )
            
for  (c  =   1 ; c  <=   5 ; c ++ )
            {
                strText 
=   " r "   +  r  +   " c "   +  c;
                oTable.Cell(r, c).Range.Text 
=  strText;
            }
        oTable.Rows[
1 ].Range.Font.Bold  =   1 ;
        oTable.Rows[
1 ].Range.Font.Italic  =   1 ;

        
// Add some text after the table.
        Word.Paragraph oPara4;
        oRng 
=  oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;
        oPara4 
=  oDoc.Content.Paragraphs.Add( ref  oRng);
        oPara4.Range.InsertParagraphBefore();
        oPara4.Range.Text 
=   " And here's another table: " ;
        oPara4.Format.SpaceAfter 
=   24 ;
        oPara4.Range.InsertParagraphAfter();

        
// Insert a 5 x 2 table, fill it with data, and change the column widths.
        wrdRng  =  oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;
        oTable 
=  oDoc.Tables.Add(wrdRng,  5 2 ref  oMissing,  ref  oMissing);
        oTable.Range.ParagraphFormat.SpaceAfter 
=   6 ;
        
for  (r  =   1 ; r  <=   5 ; r ++ )
            
for  (c  =   1 ; c  <=   2 ; c ++ )
            {
                strText 
=   " r "   +  r  +   " c "   +  c;
                oTable.Cell(r, c).Range.Text 
=  strText;
            }
        oTable.Columns[
1 ].Width  =  oWord.InchesToPoints( 2 );  // Change width of columns 1 & 2
        oTable.Columns[ 2 ].Width  =  oWord.InchesToPoints( 3 );

        
// Keep inserting text. When you get to 7 inches from top of the
        
// document, insert a hard page break.
         object  oPos;
        
double  dPos  =  oWord.InchesToPoints( 7 );
        oDoc.Bookmarks.get_Item(
ref  oEndOfDoc).Range.InsertParagraphAfter();
        
do
        {
            wrdRng 
=  oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;
            wrdRng.ParagraphFormat.SpaceAfter 
=   6 ;
            wrdRng.InsertAfter(
" A line of text " );
            wrdRng.InsertParagraphAfter();
            oPos 
=  wrdRng.get_Information
                                 (Word.WdInformation.wdVerticalPositionRelativeToPage);
        }
        
while  (dPos  >=  Convert.ToDouble(oPos));
        
object  oCollapseEnd  =  Word.WdCollapseDirection.wdCollapseEnd;
        
object  oPageBreak  =  Word.WdBreakType.wdPageBreak;
        wrdRng.Collapse(
ref  oCollapseEnd);
        wrdRng.InsertBreak(
ref  oPageBreak);
        wrdRng.Collapse(
ref  oCollapseEnd);
        wrdRng.InsertAfter(
" We're now on page 2. Here's my chart: " );
        wrdRng.InsertParagraphAfter();

        
// Insert a chart.
        Word.InlineShape oShape;
        
object  oClassType  =   " MSGraph.Chart.8 " ;
        wrdRng 
=  oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;
        oShape 
=  wrdRng.InlineShapes.AddOLEObject( ref  oClassType,  ref  oMissing,
         
ref  oMissing,  ref  oMissing,  ref  oMissing,
         
ref  oMissing,  ref  oMissing,  ref  oMissing);

        
// Demonstrate use of late bound oChart and oChartApp objects to
        
// manipulate the chart object with MSGraph.
         object  oChart;
        
object  oChartApp;
        oChart 
=  oShape.OLEFormat.Object;
        oChartApp 
=  oChart.GetType().InvokeMember( " Application " ,
         BindingFlags.GetProperty, 
null , oChart,  null );

        
// Change the chart type to Line.
         object [] Parameters  =   new  Object[ 1 ];
        Parameters[
0 =   4 // xlLine = 4
        oChart.GetType().InvokeMember( " ChartType " , BindingFlags.SetProperty,
         
null , oChart, Parameters);

        
// Update the chart image and quit MSGraph.
        oChartApp.GetType().InvokeMember( " Update " ,
         BindingFlags.InvokeMethod, 
null , oChartApp,  null );
        oChartApp.GetType().InvokeMember(
" Quit " ,
         BindingFlags.InvokeMethod, 
null , oChartApp,  null );
        
// ... If desired, you can proceed from here using the Microsoft Graph 
        
// Object model on the oChart and oChartApp objects to make additional
        
// changes to the chart.

        
// Set the width of the chart.
        oShape.Width  =  oWord.InchesToPoints( 6.25f );
        oShape.Height 
=  oWord.InchesToPoints( 3.57f );

        
// Add text after the chart.
        wrdRng  =  oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;
        wrdRng.InsertParagraphAfter();
        wrdRng.InsertAfter(
" THE END. " );

        oDoc.SaveAs(
ref  filename,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing);
        oDoc.Close(
ref  oMissing,  ref  oMissing,  ref  oMissing);
        oWord.Quit(
ref  oMissing,  ref  oMissing,  ref  oMissing);
        Response.Write(
" <script language='javascript'>alert('文档创建成功!');</script> " );
    }
    
protected   void  Button2_Click( object  sender, EventArgs e)
    {
        
object  filename  =   " F:\\wordtest\\test.doc " ;
        
object  oMissing  =  System.Reflection.Missing.Value;
        Word._Application oWord;
        Word._Document oDoc;
        oWord 
=   new  Word.Application();
        oWord.Visible 
=   true ;
        oDoc 
=  oWord.Documents.Open( ref  filename,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing, ref  oMissing);
        oDoc.ActiveWindow.Selection.WholeStory();
        oDoc.ActiveWindow.Selection.Copy();
        
this .TextBox1.Text  =  oDoc.Paragraphs.Count.ToString();
        
this .TextBox2.Text  =  oDoc.Paragraphs[ 1 ].Range.Text;
        
this .TextBox3.Text  =  oDoc.Paragraphs[ 2 ].Range.Text;
        
this .TextBox4.Text  =  oDoc.Paragraphs[ 3 ].Range.Text;
        oDoc.Close(
ref  oMissing,  ref  oMissing,  ref  oMissing);
        oWord.Quit(
ref  oMissing,  ref  oMissing,  ref  oMissing);
        Response.Write(
" <script language='javascript'>alert('数据读取成功!');</script> " );
    }
    
protected   void  Button3_Click( object  sender, EventArgs e)
    {
        
object  filename1  =   " F:\\wordtest\\test1.doc " ;
        
object  filename2  =   " F:\\wordtest\\test2.doc " ;
        
object  oMissing  =  System.Reflection.Missing.Value;
        Word._Application word1,word2;
        Word._Document doc1,doc2;
        word1 
=   new  Word.Application();
        word2 
=   new  Word.Application();
        word1.Visible 
=   true ;
        word2.Visible 
=   true ;
        doc1 
=  word1.Documents.Open( ref  filename1,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing);
        doc2 
=  word2.Documents.Open( ref  filename2,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing);
        
object  keyword  =  doc2.Paragraphs[ 2 ].Range.Words.ToString();
        
this .TextBox5.Text  =  keyword.ToString();
        word1.Application.Selection.ClearFormatting();
        
if  (word1.Application.Selection.Find.Execute( ref  keyword,
            
ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,
            
ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,  ref  oMissing,
            
ref  oMissing,  ref  oMissing))
        {
            Response.Write(
" <script language='javascript'>alert('找到关键字!');</script> " );
            
this .TextBox5.Text  =   "" ;
        }
        
else
        {
            Response.Write(
" <script language='javascript'>alert('未发现关键字!');</script> " );
        } 

        
// string titlefont1 = doc1.Paragraphs[1].Range.Font.Name.ToString();
        
// string titlefont2 = doc2.Paragraphs[1].Range.Font.Name.ToString();
        
// string titlesize1 = doc1.Paragraphs[1].Range.Font.Size.ToString();
        
// string titlesize2 = doc2.Paragraphs[1].Range.Font.Size.ToString();
         /* if (titlefont1 == titlefont2 && titlesize1 == titlesize2)
        {
            Response.Write("<script language='javascript'>alert('标题字体类型和大小都相同!');</script>");
        }
        else if (titlefont1 != titlefont2 && titlesize1 == titlesize2)
        {
            Response.Write("<script language='javascript'>alert('标题字体类型不同,大小相同!');</script>");
        }
        else if (titlefont1 == titlefont2 && titlesize1 != titlesize2)
        {
            Response.Write("<script language='javascript'>alert('标题字体类型相同,大小不同!');</script>");
        }
        else
        {
             Response.Write("<script language='javascript'>alert('标题字体类型和大小都不相同!');</script>");
        }
*/
        doc1.Close(
ref  oMissing,  ref  oMissing,  ref  oMissing);
        word1.Quit(
ref  oMissing,  ref  oMissing,  ref  oMissing);
        doc2.Close(
ref  oMissing,  ref  oMissing,  ref  oMissing);
        word2.Quit(
ref  oMissing,  ref  oMissing,  ref  oMissing);
        
    }

}

 

 

 

这张图片只是我用来写测试程序的,方便大家理解!

转载于:https://www.cnblogs.com/zhulidong/archive/2009/12/03/1616173.html

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值