如何将文本保存到word文档。 [英] how to save text to word document.

查看:194
本文介绍了如何将文本保存到word文档。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存到单词doucument,但网站只是继续加载,当我去的时候我保存文档文档已创建但没有数据,我无法操作它,我有什么可能有错误?





 私人  void  SetWordDocument()
{
object strFileName =
CleanUp(LabelFirstName.Text + _ + LabelLastName.Text + _ + DateTime.Now.ToString( yyyy-MM-dd)+
+ DropDownListDownloadCv0。 SelectedItem.Text);

object fileStream =
new FileStream(Server.MapPath( 〜/ Upload /)+
strFileName,FileMode.Create);


使用 var db = new knowitCVdbEntities())
{
var theEmpl =(来自 p db.EMPLOYEES
其中 p.username == strUserName
选择 p).FirstOrDefault();



if (theEmpl!= null
{

object missing = Missing.Value;
object start1 = 0 ;

var wordApp = new ApplicationClass();


Microsoft.Office.Interop.Word.Document myDoc = wordApp.Documents.Add( ref 缺失, ref 缺失,
ref 缺失, ref 缺失);

范围rng = myDoc.Range( ref start1, ref 缺失);

尝试
{

const char newLine =( char 11 ;

myDoc.SaveAs( ref fileStream,
ref 缺失, 参考缺失,参考缺失,参考缺失, ref 缺失,
ref 缺失, ref 缺失,参考缺失,参考缺失, ref 缺失,
参考缺失,
参考缺失,
ref 缺失, ref 缺失, ref missing);



 rng.InsertAfter(newLine.ToString()); 
rng.InsertBefore(newLine.ToString());
rng.InsertBefore(newLine + LabelPosition.Text + + LabelFirstName.Text + < span class =code-string> +
LabelLastName.Text + newLine + LabelAbout.Text);
rng.InsertBefore(newLine + Label3StrongAbout.Text);
string imageKnowItLogo = Loggo.ImageUrl;
rng.InlineShapes.AddPicture(imageKnowItLogo, ref 缺失, ref 缺失, ref 缺失);
rng.InsertBefore(newLine.ToString());



 Response.ContentType =   Application / msword; 
Response.AppendHeader( Content-Disposition attachment; filename = + strFileName);
Response.TransmitFile(Server.MapPath( 〜/ Upload /)+ strFileName) ;
Response.End();

解决方案

http://www.gemboxsoftware.com/document/articles/c-sharp-vb-net-create-write-word [ ^

I am trying to save to word doucument but the site just keep loading and when i go to were i save the document the document is created but has no data in it , and i cannot opet it, what could i have misst?


private void SetWordDocument()
        {
            object strFileName =
                 CleanUp(LabelFirstName.Text + "_" + LabelLastName.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd") +
                         "." + DropDownListDownloadCv0.SelectedItem.Text);
           
                    object fileStream =
                new FileStream(Server.MapPath("~/Upload/") +
               strFileName,FileMode.Create);
            
            
            using (var db = new knowitCVdbEntities())
            {
                var theEmpl = (from p in db.EMPLOYEES
                               where p.username == strUserName
                               select p).FirstOrDefault();



                if (theEmpl != null)
            {

                object missing = Missing.Value;
                object start1 = 0;

                var wordApp = new ApplicationClass();


                Microsoft.Office.Interop.Word.Document myDoc = wordApp.Documents.Add(ref missing, ref missing,
                                                                                     ref missing, ref missing);
                     
                Range rng = myDoc.Range(ref start1, ref missing);

                try
                {
                  
                    const char newLine = (char) 11;

                    myDoc.SaveAs(ref fileStream, 
                    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, ref missing);


rng.InsertAfter(newLine.ToString());
                    rng.InsertBefore(newLine.ToString());
                    rng.InsertBefore(newLine + LabelPosition.Text + " " + LabelFirstName.Text + " " +
                                     LabelLastName.Text + newLine + LabelAbout.Text);
                    rng.InsertBefore(newLine + Label3StrongAbout.Text);
                    string imageKnowItLogo = Loggo.ImageUrl;
                    rng.InlineShapes.AddPicture(imageKnowItLogo, ref missing, ref missing, ref missing);
                    rng.InsertBefore(newLine.ToString());


Response.ContentType = "Application/msword";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFileName);
                Response.TransmitFile(Server.MapPath("~/Upload/") + strFileName);
                Response.End(); 

解决方案

http://www.gemboxsoftware.com/document/articles/c-sharp-vb-net-create-write-word[^]


这篇关于如何将文本保存到word文档。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆