将图片保存到HTML的参考字 [英] Save Image to word of HTML reference

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

问题描述

我从我的数据库中的数据导出到从我的web应用程序,它工作正常,我的HTML格式的话,我已经插入图像插入记录,
该文件显示图像也,一切对我来说工作正常,除非我保存文件并发送给其他人..微软Word将无法找到链接到图片

反正是有保存的文档图像,这样的路径问题,不会提高

下面是我的code:StrTitle包含了所有的HTML,包括图片的链接,以及

 字符串strBody =< HTML和GT; +
            <身体GT; + strTitle +
            < /身体GT; +
            < / HTML>中;
        字符串文件名=Policies.doc;
        //对象缺少= System.Reflection.Missing.Value;
        //您可以添加任何你想添加为HTML,它会为Word文档女士生成
        Response.AppendHeader(内容类型,应用程序/ msword);
        Response.AppendHeader(内容处置,附件;文件名=+文件名);
        的Response.Write(strBody);


解决方案

由于每个图片,表格是Word / Excel中/简报类型的形状,你可以简单地使用你的程序的AlternativeText添加到您的图片,这实际上节省下载网址的URL,当你打开,它会检索它的URL和替换它。

 的foreach(NetOffice.WordApi.InlineShape S IN docWord.InlineShapes)
{
    如果(s.Type == NetOffice.WordApi.Enums.WdInlineShapeType.wdInlineShapePicture&放大器;&安培; s.AlternativeText.Contains(|))
    {
          s.AlternativeText =<您的网站的网址下载图片取代;
    }
}

这将是C#的做法,但需要对图像更多的时间。如果你为它编写一个小软件,它取代包含所有图像的 s.AlternativeText ,你可以在同一时间更换了很多照片。

  NetOffice.WordApi.InlineShape I ​​= appWord.ActiveDocument.InlineShapes.AddPicture(s.AlternativeText,假的,真正的);

它会寻找在该位置的图像。

您可以做到这一点为您与1圈我写给你整个文档。手段,如果它是一张图片,包含一些AlternativeText,那么在你里面循环使用给AddPicture功能。

编辑:Anoter解决方案,将是一个超链接设置为您的图片,这实际上会转到该图片所在的FTP服务器,当你点击图片,它会打开它,意味着他可以取代它本人(坏的,如果你有你的文档中的200张照片)

根据编辑剪贴板:

 字符串HTML = Clipboard.GetText(TextDataFormat.Html);
 File.WriteAllText(temporaryFilePath,HTML);
 NetOffice.WordApi.InlineShape I ​​= appWord.ActiveDocument.InlineShapes.AddPicture(temporaryFilePath,假的,真正的);

在Word中的剪贴板是能够改变一个给定的HTML,当你将其粘贴到表或图片转换成Word中。这工作太为Excel,但不用于PowerPoint。你可以做这样的事情为您的图片和阻力,并从数据库下降。

I export data from my database to word in HTML format from my web application, which works fine for me , i have inserted image into record, the document displays the image also , all works fine for me except when i save that file and send to someone else .. ms word will not find link to that image

Is there anyway to save that image on the document so path issues will not raise

Here is my code : StrTitle contains all the HTML including Image links as well

  string strBody = "<html>" +
            "<body>" + strTitle +
            "</body>" +
            "</html>";
        string fileName = "Policies.doc";
        //object missing = System.Reflection.Missing.Value;
        // You can add whatever you want to add as the HTML and it will be generated as Ms Word docs
        Response.AppendHeader("Content-Type", "application/msword");
        Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);
        Response.Write(strBody);

解决方案

Since every picture, table is of type shape in Word/Excel/Powerpoint, you could simply add with your program an AlternativeText to your picture, which would actually save a URL of the download URL and when you open, it will retrieve its URL and replace it.

foreach (NetOffice.WordApi.InlineShape s in docWord.InlineShapes)
{
    if (s.Type==NetOffice.WordApi.Enums.WdInlineShapeType.wdInlineShapePicture &&  s.AlternativeText.Contains("|"))
    {
          s.AlternativeText=<your website URL to download the picture>;
    }
}

This would be the C# approach, but would require more time for the picture. If you write a small software for it, which replaces all pictures which contain a s.AlternativeText, you could replace a lot of pictures at same time.

NetOffice.WordApi.InlineShape i=appWord.ActiveDocument.InlineShapes.AddPicture(s.AlternativeText, false, true);

It will look for the picture at that location.

You can do that for your whole document with the 1 loop I wrote you. Means, if it is a picture and contains some AlternativeText, then inside you loop you use the AddPicture function.

Edit: Anoter solution, would be to set a hyperlink to your picture, which would actually go to a FTP server where the picture is located and when you click on the picture, it will open it, means he can replace it by himself(bad, if you have 200 pictures in your document)

Edit according Clipboard:

 string html = Clipboard.GetText(TextDataFormat.Html);
 File.WriteAllText(temporaryFilePath, html);
 NetOffice.WordApi.InlineShape i=appWord.ActiveDocument.InlineShapes.AddPicture(temporaryFilePath, false, true);

The Clipboard in Word is capable to transform a given HTML and when you paste it to transform that table or picture into Word. This works too for Excel, but doesn't for Powerpoint. You could do something like that for your pictures and drag and drop from your database.

这篇关于将图片保存到HTML的参考字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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