Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 18, 2020. It is now read-only.
/table-to-excelPublic archive

Javascript library to create "valid" excel file from html table with styles

License

NotificationsYou must be signed in to change notification settings

linways/table-to-excel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Export HTML table to valid excel file effortlessly.This library usesexceljs/exceljs under the hood to create the excel.
(Initial version of this library was usingprotobi/js-xlsx, it can be foundhere)

Installation

Browser

Just add a script tag:

<scripttype="text/javascript"src="../dist/tableToExcel.js"></script>

Node

npm install @linways/table-to-excel --save
importTableToExcelfrom"@linways/table-to-excel";

Usage

Create your HTML table as normal.
To export content of table#table1 run:

TableToExcel.convert(document.getElementById("table1"));

or

TableToExcel.convert(document.getElementById("table1"),{name:"table1.xlsx",sheet:{name:"Sheet 1"}});

Checkthis pen for working example.

Cell Types

Cell types can be set using the following data attributes:

AttributeDescriptionPossible Values
data-tTo specify the data type of a cells : String (Default)
n : Number
b : Boolean
d : Date
data-hyperlinkTo add hyper link to cellExternal URL or hyperlink to another sheet
data-errorTo add value of a cell as error

Example:

<!-- for setting a cell type as number --><tddata-t="n">2500</td><!-- for setting a cell type as date --><tddata-t="d">05-23-2018</td><!-- for setting a cell type as boolean. String "true/false" will be accepted as Boolean--><tddata-t="b">true</td><!-- for setting a cell type as boolean using integer. 0 will be false and any non zero value will be true --><tddata-t="b">0</td><!-- For adding hyperlink --><tddata-hyperlink="https://google.com">Google</td>

Cell Styling

All styles are set usingdata attributes ontd tags.There are 5 types of attributes:data-f-*,data-a-*,data-b-*,data-fill-* anddata-num-fmt which corresponds to five top-level attributesfont,alignment,border,fill andnumFmt.

CategoryAttributeDescriptionValues
fontdata-f-nameFont name"Calibri" ,"Arial" etc.
data-f-szFont size"11" // font size in points
data-f-colorFont colorA hex ARGB value. Eg: FFFFOOOO for opaque red.
data-f-boldBoldtrue orfalse
data-f-italicItalictrue orfalse
data-underlineUnderlinetrue orfalse
data-f-strikeStriketrue orfalse
Alignmentdata-a-hHorizontal alignmentleft,center,right,fill,justify,centerContinuous,distributed
data-a-vVertical alignmentbottom,middle,top,distributed,justify
data-a-wrapWrap texttrue orfalse
data-a-indentIndentInteger
data-a-rtlText direction: Right to Lefttrue orfalse
data-a-text-rotationText rotation0 to 90
-1 to -90
vertical
Borderdata-b-a-sBorder style (all borders)ReferBORDER_STYLES
data-b-t-sBorder top styleReferBORDER_STYLES
data-b-b-sBorder bottom styleReferBORDER_STYLES
data-b-l-sBorder left styleReferBORDER_STYLES
data-b-r-sBorder right styleReferBORDER_STYLES
data-b-a-cBorder color (all borders)A hex ARGB value. Eg: FFFFOOOO for opaque red.
data-b-t-cBorder top colorA hex ARGB value.
data-b-b-cBorder bottom colorA hex ARGB value.
data-b-l-cBorder left colorA hex ARGB value.
data-b-r-cBorder right colorA hex ARGB value.
Filldata-fill-colorCell background colorA hex ARGB value.
numFmtdata-num-fmtNumber Format"0"
"0.00%"
"0.0%" // string specifying a custom format
"0.00%;\(0.00%\);\-;@" // string specifying a custom format, escaping special characters

BORDER_STYLES:thin,dotted,dashDot,hair,dashDotDot,slantDashDot,mediumDashed,mediumDashDotDot,mediumDashDot,medium,double,thick

Exclude Cells and rows

To exclude a cell or a row from the exported excel adddata-exclude="true" to the correspondingtd ortr.
Example:

<!-- Exclude entire row --><trdata-exclude="true"><td>Excluded row</td><td>Something</td></tr><!-- Exclude a single cell --><tr><td>Included Cell</td><tddata-exclude="true">Excluded Cell</td><td>Included Cell</td></tr>

Column Width

Column width's can be set by specifyingdata-cols-width in the<table> tag.data-cols-width accepts comma separated column widths specified in character count .data-cols-width="10,20" will set width of first coulmn as width of 10 charaters and second column as 20 characters wide.
Example:

<tabledata-cols-width="10,20,30">  ...</table>

Row Height

Row Height can be set by specifyingdata-height in the<tr> tag.
Example:

<trdata-height="42.5"><td>Cell 1</td><td>Cell 2</td></tr>

Release Changelog

1.0.0

Migration Guide for migrating from V0.2.1 to V1.0.0

  • Changed the backend to Exceexceljs/exceljslJS
  • Added border color
  • Option to set style and color for all borders
  • Exclude row
  • Added text underline
  • Added support for hyperlinks
  • Text intent
  • RTL support
  • Extra alignment options
  • String "true/false" will be accepted as Boolean
  • Changed border style values
  • Text rotation values changed

1.0.2

  • Fixed bug in handling multiple columns merges in a sheet

1.0.3

  • Option to specify row height

About

Javascript library to create "valid" excel file from html table with styles

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp