복붙노트

[RUBY-ON-RAILS] 워드 파일을 HTML로 변환?

RUBY-ON-RAILS

워드 파일을 HTML로 변환?

어떻게 워드 파일 즉 (DOCX 파일)에 루비 파일을 변환합니다. PDF를 들어, 우리는 보석을 새우. 그러나 워드 파일에 대한 어떤 보석이있다. 나는 너무 사용자에 대한 편집 할 수 있도록 워드 파일에 내 HTML 파일을 변환하려합니다. 이 경우 어떻게해야합니까? 나는 워드 파일에 그 파일을 변환하기 위해 계획되었다. 그것은 가능 여부 일 것이다.

해결법

  1. ==============================

    1.

    Mime::Type.register 'application/vnd.ms-word', :msword 
    

    당신이 수출 show 액션으로 싶은 말 :

    def show
      @item = Item.find params[:id]
      respond_to do |format|
        format.html # show.html.erb
        format.xml { render :xml => @item }
        format.msword { set_header('msword', "#{@item.title}.doc") }
        format.pdf do
            render :pdf => 'Coming soon...', :layout => false
        end
      end
     end
    
    def set_header(p_type, filename)
      case p_type
        when 'xls'
         headers['Content-Type'] = "application/vnd.ms-excel; charset=UTF-8'"
         headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""
         headers['Cache-Control'] = ''
    
        when 'msword'
         headers['Content-Type'] = "application/vnd.ms-word; charset=UTF-8"
         headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""
         headers['Cache-Control'] = ''
    
       end
     end
    
    YOUR HTML HERE TO EXPORT TO DOC
    AS LIKE NORMAL ERB TEMPLATE
    
  2. ==============================

    2.사용은 보석을 htmltoword. https://github.com/nickfrandsen/htmltoword

    사용은 보석을 htmltoword. https://github.com/nickfrandsen/htmltoword

    그것은 11 월 2015 년 이후 업데이트,하지만 잘 작동되지 않았습니다.

  3. from https://stackoverflow.com/questions/18372210/convert-html-to-word-file by cc-by-sa and MIT license