C#代码在C#中的fileupload

C#代码在C#中的fileupload

本文介绍了C#代码在C#中的fileupload Microsoft world doc中更改word文档中存在的数据的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#代码更改word文档中word文档中存在的数据的字体大小在asp.net或c#中的Microsoft World文档可能与否。我尝试下面的代码不能正常工作告诉我



我尝试了什么:



c# Code to change the font size of data present in word document in fileUpload Microsoft World doc in asp.net or c# its possible or not.Iam trying below code its not working Tell me

What I have tried:

protected void btnUpload_Click(object sender, EventArgs e)
        {
            string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            FontFamily family = new FontFamily("Times New Roman");
            Font font = new Font(family, 16.0f,
            FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);

            FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
          //  Response.Redirect(Request.Url.AbsoluteUri);
        }

推荐答案

protected void btnUpload_Click(object sender, EventArgs e)
{
    string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);

    FileUpload1.PostedFile.SaveAs(Server.MapPath("~/") + fileName);

    fileName = Server.MapPath("~/") + fileName;
    using (var document = WordprocessingDocument.Open(fileName, true))
    {
        RunProperties runProp = new RunProperties();

        RunFonts runFont = new RunFonts();           // Create font
        runFont.Ascii = "Arial";                     // Specify font family

        DocumentFormat.OpenXml.Wordprocessing.FontSize size = new DocumentFormat.OpenXml.Wordprocessing.FontSize();
        size.Val = new StringValue("48");  // 48 half-point font size
        runProp.Append(runFont);
        runProp.Append(size);

        Run r = document.MainDocumentPart.Document.Descendants<Run>().First();
        r.PrependChild<RunProperties>(runProp);
        document.MainDocumentPart.Document.Save();
    }


这篇关于C#代码在C#中的fileupload Microsoft world doc中更改word文档中存在的数据的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:29