GVKun编程网logo

php在程序中将网页生成word文档并提供下载的代码(php把某个网页生成图片)

27

此处将为大家介绍关于php在程序中将网页生成word文档并提供下载的代码的详细内容,并且为您解答有关php把某个网页生成图片的相关问题,此外,我们还将为您介绍关于C#实现word文件下载的代码、C#生

此处将为大家介绍关于php在程序中将网页生成word文档并提供下载的代码的详细内容,并且为您解答有关php把某个网页生成图片的相关问题,此外,我们还将为您介绍关于C#实现word文件下载的代码、C#生成Word文档代码示例、iText生成word文件,生成word文档后,页码如何取出来!、java Servlet 下载 itext 生成的2003 word 文档(java生成word文档3)的有用信息。

本文目录一览:

php在程序中将网页生成word文档并提供下载的代码(php把某个网页生成图片)

php在程序中将网页生成word文档并提供下载的代码(php把某个网页生成图片)

在这篇文章中主要解决两个问题:

1:在PHP中如何把html中的内容生成到word文档中
2:PHP把html中的内容生成到word文档中时,不居中显示问题,即会默认按照web视图进行显示。
3:PHP把html中的内容生成到word文档中时,相关样式不兼容问题 正文:
代码如下:
echo '
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
Print

总结

以上是小编为你收集整理的php在程序中将网页生成word文档并提供下载的代码全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

word文档网页网页

C#实现word文件下载的代码

C#实现word文件下载的代码

效果:

思路:

简单的有两种方式下载,一种是流下载,一种是WriteFile下载。以下是使用WriteFile下载。

代码:

复制代码 代码如下:

protected void LinkButton1_Click(object sender,EventArgs e)
        {
            try
            {
                //WriteFile实现下载(word)
                string fileName = "qingpingguo.docx";//客户端保存的文件名
                string filePath = Server.MapPath("~\\excel\\" + tb1.Text);//路径

                FileInfo fileInfo = new FileInfo(filePath);
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                response.addheader("Content-disposition","attachment;filename=" + fileName);
                response.addheader("Content-Length",fileInfo.Length.ToString());
                response.addheader("Content-transfer-encoding","binary");
                Response.ContentType = "application/octet-stream";
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                Response.WriteFile(fileInfo.FullName);
                Response.Flush();
                Response.End();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

            /*************以下为流方式下载****************/
            //string fileName = "aaa.txt";//客户端保存的文件名
            //string filePath = Server.MapPath("DownLoad/aaa.txt");//路径

            ////以字符流的形式下载文件
            //FileStream fs = new FileStream(filePath,FileMode.Open);
            //byte[] bytes = new byte[(int)fs.Length];
            //fs.Read(bytes,bytes.Length);
            //fs.Close();
            //Response.ContentType = "application/octet-stream";
            ////通知浏览器下载文件而不是打开
            //response.addheader("Content-disposition","attachment;  filename=" + HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8));
            //Response.BinaryWrite(bytes);
            //Response.Flush();
            //Response.End();

        }

C#生成Word文档代码示例

C#生成Word文档代码示例

public bool CreateWordFile(string _filename,"数据List或者你C#要写的数据")
    {
            #region 开始生成Word
      try
      {

        string strtitle = "任务导出";
        object oEndOfDoc = "//endofdoc";
        Object nothing = System.Reflection.Missing.Value;
        Object filename = _filename;
        //创建Word文档

        Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
        Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref nothing,ref nothing,ref nothing);


        //设置页眉
        WordApp.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView;
        WordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;
        WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("WPFOA任务导出");
        WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdalignParagraphRight;//设置右对齐
        WordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;//跳出页眉设置
        //任务导出------名字
        Word.Paragraph oPara1;
        oPara1 = WordDoc.Content.Paragraphs.Add(ref nothing);
        oPara1.Range.Text = strtitle;
        oPara1.Range.Font.Bold = 1;
        oPara1.Range.Font.Name = "宋体";
        oPara1.Range.Font.Size = 20;
        oPara1.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdalignParagraphCenter;
        oPara1.Format.SpaceAfter = 5;  //24 pt spacing after paragraph.
        oPara1.Range.InsertParagraphAfter();
        #region 循环每个表

        foreach (var v in lst_task)
        {
          #region 循环每一个列,产生一行数据
          //描述信息
          Word.Paragraph oPara3;
          object oRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
          oPara3 = WordDoc.Content.Paragraphs.Add(ref oRng);
          oPara3.Range.Text = "";
          oPara3.Range.Font.Bold = 0;
          oPara3.Range.Font.Name = "宋体";
          oPara3.Range.Font.Size = 9;
          oPara3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdalignParagraphCenter;
          oPara3.Format.SpaceBefore = 1;
          oPara3.Format.SpaceAfter = 1;
          oPara3.Range.InsertParagraphAfter();

          //插入表格     
          Word.Table newTable;
          Word.Range wrdRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
          newTable = WordDoc.Tables.Add(wrdRng,5,4,ref nothing);
          newTable.Columns[1].Width = 60;
          newTable.Columns[2].Width = 145;
          newTable.Columns[3].Width = 80;
          newTable.Columns[4].Width = 145;
          newTable.Borders.OutsideLinestyle = Microsoft.Office.Interop.Word.WdLinestyle.wdLinestyleSingle;
          newTable.Borders.InsideLinestyle = Microsoft.Office.Interop.Word.WdLinestyle.wdLinestyleSingle;

          //填充表格内容
          newTable.Cell(1,1).Range.Text = "项目名称";
          newTable.Cell(1,2).Range.Text = "1";
          newTable.Cell(1,3).Range.Text = "模块名称";
          newTable.Cell(1,4).Range.Text = "2";
          newTable.Cell(2,1).Range.Text = "负责人名";
          newTable.Cell(2,2).Range.Text = "3";
          newTable.Cell(2,3).Range.Text = "状态";
          newTable.Cell(2,4).Range.Text = "4";
          newTable.Cell(3,1).Range.Text = "发布时间";
          newTable.Cell(3,2).Range.Text = "5";
          newTable.Cell(3,3).Range.Text = "要求完成时间";
          newTable.Cell(3,4).Range.Text = "6";
          newTable.Cell(4,1).Range.Text = "完成时间";
          newTable.Cell(4,2).Range.Text = "7";
          newTable.Cell(4,3).Range.Text = "分配人";
          newTable.Cell(4,4).Range.Text = "8";
          newTable.Cell(5,1).Range.Text = "任务描述";
          newTable.Cell(5,2).Merge(newTable.Cell(5,4));
          newTable.Cell(5,2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdalignParagraphLeft;
          newTable.Cell(5,2).Range.Text = "12313213123213";
          #endregion
        }


        WordDoc.SaveAs(ref filename,ref nothing);

        WordDoc.Close(ref nothing,ref nothing);
        WordApp.Quit(ref nothing,ref nothing);
        #endregion
        //关闭WinWord进程
        System.Diagnostics.Process[] MyProcess = System.Diagnostics.Process.GetProcessesByName("WINWORD");
        MyProcess[0].Kill();
        return true;

      }
      catch
      {

        System.Diagnostics.Process[] MyProcess = System.Diagnostics.Process.GetProcessesByName("WINWORD");
        MyProcess[0].Kill();
        return false;
      }
      #endregion
    }


iText生成word文件,生成word文档后,页码如何取出来!

iText生成word文件,生成word文档后,页码如何取出来!

@红薯 你好,想跟你请教个问题:

    我用的是iText来生成word文件,文件可以生成,现在有一个问题就是跨页问题,我生成表格后如果跨页后,也想在第二页将表格中的表头也插入到第二页中,我想根据页码来判断,现在就是页码我取不出来,但生成页脚后页码能显示出来,我取页码就取不出来。请问有什么办法吗?

document.open();

RtfPageNumber number = new RtfPageNumber();
   Paragraph parafooter = new Paragraph();
   parafooter.add(new Phrase("第"));
   parafooter.add(number);
   System.out.println("----number---"+number);
   
   parafooter.add(new Phrase("页 共"));
   parafooter.add(new RtfTotalPageNumber());
   parafooter.add(new Phrase("页"));

   HeaderFooter footer = new RtfHeaderFooter(parafooter);
   footer.setAlignment(Element.ALIGN_RIGHT);
   footer.setBorder(Rectangle.NO_BORDER);
   document.setFooter(footer);
   document.close();

 

急!急!急!

 

java Servlet 下载 itext 生成的2003 word 文档(java生成word文档3)

java Servlet 下载 itext 生成的2003 word 文档(java生成word文档3)

package cn.net.seek.servlet.legalidea;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.rtf.RtfWriter2;

import cn.net.seek.service.LegalDraftService;

public class ExportAllIdeaServlet extends HttpServlet {

	private static final long serialVersionUID = -6937472436989564187L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String puid = request.getParameter("puid");
		LegalDraftService service=new LegalDraftService();
		String title = service.findTitleByPuid(puid);
		OutputStream toClient=new BufferedOutputStream(response.getOutputStream());
		response.addHeader("Content-Disposition", "attachment;filename="
				+ new String(title.getBytes("gbk"), "iso8859-1") + ".doc");
		response.setContentType("application/vnd.ms-word");
		Document document = new Document(PageSize.A4);
		RtfWriter2.getInstance(document, toClient);
		document.open();
		try {
			service.downAllIdeaByPuid(puid, title, document);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		document.close();
		toClient.flush();
		toClient.close();
	}
}

关于php在程序中将网页生成word文档并提供下载的代码php把某个网页生成图片的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于C#实现word文件下载的代码、C#生成Word文档代码示例、iText生成word文件,生成word文档后,页码如何取出来!、java Servlet 下载 itext 生成的2003 word 文档(java生成word文档3)等相关知识的信息别忘了在本站进行查找喔。

本文标签:

上一篇记录PHP错误日志 display_errors与log_errors的区别(php错误日志在哪里)

下一篇php排序算法(冒泡排序,快速排序)(php冒泡排序和快速排序)