Coder Social home page Coder Social logo

shanamaid / sheetjs-style Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sheetjs/sheetjs

104.0 2.0 36.0 53.96 MB

support set cell style for sheetjs! 😈

License: Apache License 2.0

JavaScript 98.51% HTML 0.49% Shell 0.08% Makefile 0.31% CSS 0.15% Batchfile 0.03% TypeScript 0.43%
sheetjs js-xlsx style excel excel-export xlsx xlsx-style sheetjs-style cell-style

sheetjs-style's Introduction

Sheetjs-style

version license downloads downloads-month

support set cell style for sheetjs!

API is the same as sheetjs!

install

npm install sheetjs-style

How to Use?

Please read SheetJs Documents!

How to set cell Style?

for example:

const XLSX = require('sheetjs-style');
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet([{
  0: 0,
  1: 1,
  2: 2
}], {
  header: ['0', '1', '2'],
});

ws["A1"].s = { // set the style for target cell
  font: {
    name: '宋体',
    sz: 24,
    bold: true,
    color: {
      rgb: "FFFFAA00"
    }
  },
};

XLSX.utils.book_append_sheet(wb, ws, 'sheet1'); // add worksheet to workbook

XLSX.writeFile(wb, 'test.xlsx'); // write workbook

单元格设置样式

Cell Styles

Cell styles are specified by a style object that roughly parallels the OpenXML structure. The style object has five top-level attributes: fill, font, numFmt, alignment, and border.

Style Attribute Sub Attributes Values
fill patternType "solid" or "none"
fgColor COLOR_SPEC
bgColor COLOR_SPEC
font name "Calibri" // default
sz "11" // font size in points
color COLOR_SPEC
bold true or false
underline true or false
italic true or false
strike true or false
outline true or false
shadow true or false
vertAlign true or false
numFmt "0" // integer index to built in formats, see StyleBuilder.SSF property
"0.00%" // string matching a built-in format, see StyleBuilder.SSF
"0.0%" // string specifying a custom format
"0.00%;\\(0.00%\\);\\-;@" // string specifying a custom format, escaping special characters
"m/dd/yy" // string a date format using Excel's format notation
alignment vertical "bottom" or "center" or "top"
horizontal "left" or "center" or "right"
wrapText true or false
readingOrder 2 // for right-to-left
textRotation Number from 0 to 180 or 255 (default is 0)
90 is rotated up 90 degrees
45 is rotated up 45 degrees
135 is rotated down 45 degrees
180 is rotated down 180 degrees
255 is special, aligned vertically
border top { style: BORDER_STYLE, color: COLOR_SPEC }
bottom { style: BORDER_STYLE, color: COLOR_SPEC }
left { style: BORDER_STYLE, color: COLOR_SPEC }
right { style: BORDER_STYLE, color: COLOR_SPEC }
diagonal { style: BORDER_STYLE, color: COLOR_SPEC }
diagonalUp true or false
diagonalDown true or false

COLOR_SPEC: Colors for fill, font, and border are specified as objects, either:

  • { auto: 1} specifying automatic values
  • { rgb: "FFFFAA00" } specifying a hex ARGB value
  • { theme: "1", tint: "-0.25"} specifying an integer index to a theme color and a tint value (default 0)
  • { indexed: 64} default value for fill.bgColor

BORDER_STYLE: Border style is a string value which may take on one of the following values:

  • thin
  • medium
  • thick
  • dotted
  • hair
  • dashed
  • mediumDashed
  • dashDot
  • mediumDashDot
  • dashDotDot
  • mediumDashDotDot
  • slantDashDot

Borders for merged areas are specified for each cell within the merged area. So to apply a box border to a merged area of 3x3 cells, border styles would need to be specified for eight different cells:

  • left borders for the three cells on the left,
  • right borders for the cells on the right
  • top borders for the cells on the top
  • bottom borders for the cells on the left

Thanks

sheetjs js-xlsx

sheetjs-style's People

Contributors

berzniz avatar biggestt avatar dman577 avatar dxcx avatar finesse avatar hmalphettes avatar jimmywarting avatar kawanet avatar nathanathan avatar notchris avatar rcfrias avatar reviewher avatar robbannn avatar rohankulshreshtha avatar ryancavanaugh avatar sandersn avatar sebastianmetzger avatar sebmaster avatar shanamaid avatar sheetjsdev avatar siguza avatar starmon00 avatar tmburnell avatar tmcw avatar tmiller00 avatar tombousso avatar tsbxmw avatar vjau avatar vvaldersteins avatar wolfgang42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sheetjs-style's Issues

Unable to use

Hi, I want to know what are the rules of usage, I have installed the dependency on my project, but it the styles are not working, what do I import or does it suppose to add styles by just adding the dependency?

A brief example of how to setup will be appreciated,

Thanks

Styles not working

Styles are not working it seems. Or maybe I'm not using this properly

I import and I'm using the project like this


....
const wb = XLSX.utils.book_new();
  const ws = XLSX.utils.aoa_to_sheet(fullData);

  ws["A1"].s = {
    fill: {
      bgColor: {rgb: 'FF000000'}
    },
    font: {
      name: '宋体',
      sz: 24,
      bold: true,
      color: {rgb: "FFFFAA00"}
    },
  };

I tried also with different fonts. I tried without the font block and just see if I could fillt the cell, but the A1 cell is showing unformatted

How we should use this? Seems like it is being totally ignored

Many thanks!

Range select ?

The docs describe how to select a single cell: ws["A1"].s. But how can I select a range like A:A or A1:B5 to apply style?

Border on merge columns applies only on the first column

So I have two columns that I merged.

const form = [
  ['Hello World', null]
]

const worksheet = XLSX.utils.json_to_sheet(form, {
  skipHeader: true
})

Merge the cells

worksheet['!merges'] = [
  {
    s: { r: 0, c: 0 },
    e: { r: 0, c: 1 }
  }
]

then add the styles

  worksheet.A1.s = {
    border: {
      bottom: {
        style: 'thin',
        rgb: '#000'
      }
    }
  }
  worksheet.B1.s = {
    border: {
      bottom: {
        style: 'thin',
        rgb: '#000'
      }
    }
  }

The result
image

Undeclared variable QUOTE

Hi! i'm having a runtime exception with this variable, it throws "QUOTE is not defined". Pleaseo, i need your help. I'm working with esbuild and typescript

Undeclared variable QUOTE

Hi, there's an error in the line 21524 of the file xlsx.js. The variable QUOTE is not declared, and this generates an error when you build a project using this library.

var APOS = "'"; QUOTE = '"'

It looks like a typo, I just changed the ; for a , and it works perfectly.

Thanks.

Quote is not defined

I followed the basic example on the readme and my app stops working. It points to this line in xlsx.js file. It seems a semi-colon instead of a coma got in the way.
I'm using this library on the frontend so the import statement is different. But the rest of the code is from the readme.. What should I do? Thank you.

import XLSX from "sheetjs-style";

image

This package does not have latest updates from SheetJS

Hi,

I noticed in the homepage of this NPM package Github repo the following:
"This branch is 13 commits ahead, 276 commits behind SheetJS/sheetjs:master."

It seems as though this package is somewhat behind with regards to the updates from SheetJS package which is regularly updated. Can this NPM package be kept up to date with SheetJS changes so that it is more reliable. The idea of having color styles being added to excel exports is a great one that I am currently using for my project, so it would be nice if this package is kept up to date with SheetJS.

Cheers!
Farhan Kassam.

questions on merged cells styling

firstly, thank you for open sourcing this great project.

I have one question on merged cell's style,

Supposed I have merged area from A1 to A10

the border style could only be applied to A1, and 2~10 is not defined in the Sheets.SheetN object.

How could I apply border's style to the merged cell in this circumstance.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.