protobi / js-xlsx

XLSX / XLSM / XLSB (Excel 2007+ Spreadsheet) / ODS parser and writer
http://oss.sheetjs.com/js-xlsx
Other
826 stars 416 forks source link

Partial Styles #14

Open kimberlydb opened 8 years ago

kimberlydb commented 8 years ago

Wondering how I could have a cell where only part of the cell is styled. eg:

{ v: "this is my BOLD text" s: { font: { bold: true } } }

VincentGuinaudeau commented 8 years ago

I've never try this, but the documentation show the cell.h attribute for "rich text" via html.

You could try with something like this :

var my_bold_cell = {
    v: "this is my BOLD text",
    h: "this is my <b>BOLD</b> text"
}
jmorrisIII commented 7 years ago

@kimberlydb did you get this to work?

kimberlydb commented 7 years ago

I did not. I ended up splitting them into different cells and styling them separately.

jmorrisIII commented 7 years ago

@kimberlydb thanks for getting back with me. Looks like the only option for now.

nikhil18sharma commented 6 years ago

Hi @kimberlydb, Can you please share your code on how to add style to cells? I am unable to do the same. Here is my code below,

import * as XLSX from 'xlsx';

const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(jsonData); const workbook: XLSX.WorkBook = { Sheets: { 'attributes list': worksheet }, SheetNames: ['attributes list'], }; worksheet.A1.v = "Attribute Name"; worksheet.A1.s = { font: { bold: true } }; XLSX.writeFile(workbook, "attributeList" + ".xlsx");

The exported file do not show cell A1 as bold. I tried using XLSX.writeFile(workbook, "attributeList" + ".xlsx", { cellStyles: true }); but did not work.

I am stuck on this long time. Will appreciate your help.

Thanks.

kimberlydb commented 6 years ago

@nikhil18sharma eg.

var headerText = {
  font: {
    color: {rgb: "FF4F81BD"}, 
    name: "Franklin Gothic Medium", sz: 16 
  },
  border: {
    left: {
      color: {auto: 1}
    },
    top: {
      color: {auto: 1}
    }, 
    right: {
      color: {auto: 1}
    } 
  }, 
  fill: { 
    fgColor: { rgb: "FFFFFFFF"}
  }
};
workbook.setCell(fwSheets.intro, 0, 2, {v: "INTRO TEXT", s: headerText });