2011-04-16 75 views
0

我想允許doc文件的下載工具,但動態必須添加客戶端名稱,但不使用Microsoft Word對象庫。 這裏是secnario: -閱讀doc文件除了使用mircorsoft字對象庫

1)下載鏈接 2)點擊它應該開始下載doc文件,我已經保存在我的共享位置在我的服務器上。 3)在下載之前,它實際上應該在doc文件插入註冊用戶名,然後讓他去下載。

存儲在共享位置的doc文件沒有客戶端名稱,但有一個空白,以便動態填充客戶端名稱。

但未使用微軟字12.0對象庫

這可能嗎?如果是,那麼該怎麼去。

+0

你說的是直接使用文檔嗎?請參閱[本](http://www.dq.winsila.com/tips-tricks/exploring-the-insides-of-a-docx-word-document.html)以開始使用。 – jonsca 2011-04-16 07:25:00

+0

的Aspose詞能做到這一點,但它的成本錢。 – Magnus 2011-04-16 10:33:09

回答

0
protected void B1(object s, EventArgs e) 
{ 
if (FileUpload1.HasFile) 
{ 

string FTSI = @"c:\temp\doc\"; 
string FP = folder_to_save_in + FileUpload1.FileName; 

FileUpload1.SaveAs(FP); 


Word.ApplicationClass wordApplication = new Word.ApplicationClass(); 


object oNO = System.Reflection.Missing.Value; 
object oFP = FP; 
Word.Document doc = wordApplication.Documents.Open(ref oFP, 
ref oNO, ref oNO, ref oNO, ref oNO, ref oNO, 
ref oNO, ref oNO, ref oNO, ref oNO, ref oNO, 
ref oNO, ref oNO, ref oNO, ref oNO, ref oNO); 


string newfilename = folder_to_save_in + FileUpload1.FileName.Replace(".doc", ".html"); 
object oNF = newfilename; 
object oFR = Word.WdSaveFormat.wdFormatHTML; 
object oEN = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8; 
object oEN = Word.WdLineEndingType.wdCRLF; 

wordApplication.ActiveDocument.SaveAs(ref oNF, ref oFR, ref oNO, 
ref oNO, ref oNO, ref oNO, ref oNO, ref oNO, ref oNO, 
ref oNO, ref oNO, ref oNO, ref oNO, 
ref oNO, ref oNO, ref oNO); 


Label1.Text = "Uploaded file successfully!"; 

doc.Close(ref oNO, ref oNO, ref oNO); 
} 
}