1.0.10 • Published 11 months ago

tidesquare-xlsx-merge v1.0.10

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

Core package: xlsx-js-style

Publish Package (using yarn):

  1. yarn login
  2. yarn build
  3. yarn publish

Example

Input

const data = [
  { name: "A", age: 16, mark: 7, province: "Da Nang", district: "Hoang Sa" },
  { name: "B", age: 12, mark: 9.25, province: "Ha Noi", district: "Thanh Xuan" },
  { name: "C", age: 12, mark: 10, province: "Ha Noi", district: "Cau Giay" },
  { name: "D", age: 14, mark: 10, province: "Bac Ninh", district: "Que Vo" },
];

const columns: Column[] = [
  { id: 1, field: "name", title: "Tên", align: 'center', width: 100 },
  { id: 2, field: "age", title: "Tuổi", align: 'right', width: 50, isMerge: true },
  { id: 3, field: "mark", title: "Điểm", type: 'currency', align: 'right', fraction: 1, width: 50 },
  {
    id: 4,
    field: "",
    title: "Địa chỉ",
    children: [
      { id: 41, field: "province", title: "Tỉnh thành", align: 'left', width: 100, isMerge: true },
      { id: 42, field: "district", title: "Quận huyện", align: 'left', width: 100 },
    ],
  },
];

const config: Config = {
  alignKey: 'align',
  widthKey: 'width',
  mergedKey: 'isMerge',
  fractionKey: 'fraction',
  unit: 'wpx',
  widthRate: 1
}
// MyComponent.tsx
const MyComponent = () => {
  const [dataExport, setDataExport] = useState([]);

  const handleConvertData = () => {
    // logic convert data
    const nextData = cloneDeep(data);
    nextData[0].name = 'A-converted';

    setDataExport(nextData);
  }

  return (
    <ExcelExportTSQ
      data={dataExport}
      columns={columns}
      fileName="student"
      config={config}
      mergedFieldCondition="age"
      onLoading={() => console.log("start")}
      onSuccess={() => console.log("end")}
      onEmpty={() => console.log("empty data")}
      onConvert={handleConvertData}
    >
      <CustomButton buttonType="excel" text={text} /> // children
    </ExcelExportTSQ>
  );
}

Result

Demo on stackblitz

ExcelExportTSQ Properties:

PropertyRequimentDefaultTypeDescription
datatrue-object[]Data record array to be displayed.
columnstrue-Column[]Columns of table.
fileNametrue-stringExcel file name (.xlsx).
configtrue-ConfigColumn key mapping to excel fields.
childrentrue-JSX.ElementElement receives onClick() event.
onLoadingtrue-function()Callback executed when children element is clicked.
onSuccesstrue-function()Callback executed when data is exported successfully.
onEmptytrue-function()Callback executed when empty data.
onConvertfalseundefinedfunction()Callback converted data before export.
mergedFieldConditionfalseundefinedstringCondition field to merge cell. Ex: orderCode, bookingCode,...

Column

PropertyRequimentDefaultTypeDescription
idtrue-numberUnique Id.
fieldtrue-stringField mapping to data.
titletrue-stringHeader title.
childrenfalseundefinedColumn[]Nested Columns.
typefalsegeneralcurrency | date | generalValues type.
[key: number \| string]--any-

Config

PropertyRequimentDefaultTypeDescription
alignKeytrue-stringColumn key mapping to align. Ex: align, textAlign, excelAlgin,...
mergedKeytrue-stringColumn key mapping to merge. Ex: mergeCell, isMerge,...
fractionKeytrue-stringColumn key mapping to format float number (number of characters after the comma). Ex: fraction, excelFraction,...
widthKeytrue-stringColumn key mapping to width. Ex: width, excelWidth,...
widthRatefalse1numberRatio of width in excel to that in the original column.
widthDefaultfalse80 | 14numberWidth default by unit: wpx: 80, wch: 14.
unitfalsewpxwpx | wchUnit of width.
1.0.9

11 months ago

1.0.10

11 months ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago