zoukankan      html  css  js  c++  java
  • 图片插入word

     var filename = "餐桌二维码信息_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc";
                string path = Server.MapPath("~/Templates/Temp/" + filename);
                Document doc = new Document();
                DocumentBuilder builder = new DocumentBuilder(doc);
                //清除设置  
                builder.PageSetup.ClearFormatting();
                builder.StartTable();
                builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //标题居中  
                builder.Bold = true;//字体加粗  
                builder.Font.Size = 16; //字体大小  
                builder.RowFormat.Height = 30;
                builder.InsertCell();//插入Table单元格  
                builder.CellFormat.Width = 400;
                builder.CellFormat.Borders.LineStyle = LineStyle.Hairline;
                builder.CellFormat.Borders.Color = Color.White;
                builder.Writeln("测试导入word");
                builder.EndRow();
                //插入图片
                List<string> list = new List<string>{"0.jpg","1.jpg", "2.jpg", "3.jpg"};
                foreach(var item in list)
                {
                    var bt = GetIMGbyte(item);
                    Insert(builder,bt,100,100,"测试插入",true);

                }
                builder.EndTable();
                doc.Save(path);
                return View();

    private void Insert(DocumentBuilder builder, byte[] bt = null, int width = 0, int height = 0, string str = "", bool isimg = true)
            {
                //设置表格行高度  
                builder.RowFormat.Height = height;
                //插入Table单元格  
                builder.InsertCell();
                //Table单元格边框线样式  
                builder.CellFormat.Borders.LineStyle = LineStyle.Hairline;
                builder.CellFormat.Borders.Color = Color.White;
                //设置单元格宽度  
                builder.CellFormat.Width = width;
                //此单元格中内容垂直对齐方式  
                builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
                builder.CellFormat.HorizontalMerge = CellMerge.None;
                builder.CellFormat.VerticalMerge = CellMerge.None;
                //此单元格中内容水平对齐方式  
                builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
                //字体大小  
                builder.Font.Size = 12;
                //是否加粗  
                builder.Bold = true;
                //向此单元格中添加内容  
                if (isimg)
                {
                    builder.InsertImage(bt, width, height);
                    builder.Writeln(" ");
                }
                builder.Writeln(str);
            }


    private byte[] GetIMGbyte(string PicturePath)
            {
                var imgPath = Server.MapPath("~/Content/Images/" + PicturePath);
                //将需要存储的图片读取为数据流
                FileStream fs = new FileStream(imgPath, FileMode.Open, FileAccess.Read);
                Byte[] btye2 = new byte[fs.Length];
                fs.Read(btye2, 0, Convert.ToInt32(fs.Length));
                fs.Close();
                return btye2;
            }

  • 相关阅读:
    概述各种事务隔离级别发生的影响
    linux内核的经典书籍
    sso 登录,网页跳转的实现方式
    初探移动网站的架构和设计
    C# PrintDocument 打印
    .Text分页技术(1)分页的存储过程分析
    SQL2008使用CTE递归查询批量插入500万数据
    自己写的Web服务器
    OMCS 语音视频框架
    ESFramework4.x
  • 原文地址:https://www.cnblogs.com/xgyweb/p/6912515.html
Copyright © 2011-2022 走看看