pat coding

[Ruby excel] write_xlsx 를 통한 엑셀 설정 본문

Language/RubyOnRails

[Ruby excel] write_xlsx 를 통한 엑셀 설정

uuukpyo 2020. 1. 7. 10:49
728x90

write_xlsx

루비온레일즈에는 excel 읽고 쓰기, 내보내기가 가능한 gem 들이 있다.

그 중 내보내기 gem 인 write_xlsx 를 알아보자.


book = WriteXLSX.new(파일 경로) : 파일 생성
sheet = book.add_worksheet : 워크 시트 생성
book.add_format : 옵션(텍스트 및 색 등)
sheet.write_string(행, 열, 내용, 옵션) : 셀 추가 
sheet.freeze_panes(고정할 셀) : 헤더로 고정
sheet.set_column : 열 설정
sheet.set_row : 행 설정

WriteXLSX.new 를 통해 파일 경로를 설정해주면 원하는 곳에 파일이 생성된다.

file_path = "/home/ubuntu/download/xls/#{filename}"

filename 으로 들어가는 곳에 파일명을 입력해주어도 된다.

 


자세한 설정 및 사용법은 공식 문서를 참고하세요.

 

http://cxn03651.github.io/write_xlsx/

 

WriteXLSX

CONTENTS DESCRIPTION The WriteXLSX rubygem can be used to create an Excel file in the 2007+ XLSX format. The WriteXLSX and this document is ported from Perl module Excel::Wirter::XLSX. If you have any problem and question, please contact me. The XLSX forma

cxn03651.github.io

https://xlsxwriter.readthedocs.io/index.html

 

Creating Excel files with Python and XlsxWriter — XlsxWriter Documentation

 

xlsxwriter.readthedocs.io

 

728x90

'Language > RubyOnRails' 카테고리의 다른 글

[Ruby] Array 정리  (0) 2020.02.04
rails controller  (0) 2020.01.09
Active Record의 정의  (1) 2019.12.24
[Ruby]텍스트 치환  (0) 2019.12.19
[Ruby]값 확인 메소드 정리  (0) 2019.12.04
Comments