在AlaSQL / JS-XLSX Excel导出上定义单元格格式 [英] Define cell format on AlaSQL/JS-XLSX Excel Export

查看:1470
本文介绍了在AlaSQL / JS-XLSX Excel导出上定义单元格格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在AlaSQL导出到Excel时定义单元格格式?

Is it possible to define cell format on AlaSQL export to Excel?

我正在维护一个使用AlaSQL将网格数据导出到Excel的系统。问题是Excel数据没有转换为NUMBER。 DATE可以,但数字类型始终显示为常规。通过在JS中强制转换为Number类型,消息Number as as被存储在xls文件中。

I'm maintaining a system that exports grid data to Excel using AlaSQL. The problem is that Excel data is not being converted to NUMBER. DATE is OK, but Numeric types always appears as General. By forcing a convertion to Number type in JS, the message "Number stored as Text" is shown on xls file.

我认为使用js可以更容易地解决这个问题-xlsx直接,但它会在项目中产生很多变化,这不是一个选项。

I think it would be easier solving this problem using js-xlsx directly, but it would generate lots of changes in project and this is not an option.

我需要使用这样的东西,如 jsFiddle ,将json选项传递给alasql函数。

I need to use something like shown in this jsFiddle, passing json options to alasql function.

这是一个简单的代码作为问题示例:

Here is a simple code as a problem example:

    <head>

    <script src="http://cdn.jsdelivr.net/alasql/0.2/alasql.min.js"></script> 
    <script src="http://alasql.org/console/xlsx.core.min.js"></script>

</head>

<script>

  function download() {

    var opts = {
        sheetid: 'Default',
        headers: true
    };

    alasql.fn.to_number = function(val){
        return new Number(val);
    };

    var query = 'SELECT to_number("1") as NumericColumn INTO XLSX("Test.xlsx", ?)';

    alasql(query, [opts, function data(){}]);

  };

</script>

感谢您的关注。

推荐答案

AlaSQL具有带着色功能的XLSXML()导出功能:

AlaSQL has XLSXML() export function with coloring functionality:

var data = [{city:"London",population:5000000}, 
    {city:"Moscow",population:12000000},
    {city:"Mexico",population:20000000}, 
    {city:"New York",population:20000000}, 
];

var opts = {
  headers:true, 
  column: {style:{Font:{Bold:"1"}}},
  rows: {1:{style:{Font:{Color:"#FF0077"}}}},
  cells: {1:{1:{
    style: {Font:{Color:"#00FFFF"}}
  }}}
};
alasql('SELECT * INTO XLSXML("restest280b.xls",?) FROM ?',[opts,data]);

这里您可以为工作表中的任何列,行或单元格定义样式。

Here you can define style for any column, row, or cell in the sheet.

这篇关于在AlaSQL / JS-XLSX Excel导出上定义单元格格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆