【问题标题】:Kendo Grid for Angular 2 Excel export date formattingKendo Grid for Angular 2 Excel 导出日期格式
【发布时间】:2018-04-26 15:29:05
【问题描述】:

当我们尝试从 Kendo UI Grid for Angular 导出网格数据时,其中一个网格列(日期列)不会格式化实际的日期值。 这是我的代码。

<kendo-excelexport [data]="products" [group]="group" fileName="products.xlsx" [headerPaddingCellOptions]="headerPaddingCells" #excelexport>
    <kendo-excelexport-column field="dateofService" title="Date(s) of Service" [width]="170"  [cellOptions]="{ format: 'yy-MM-dd hh:mm:ss' }"  >
    </kendo-excelexport-column>
    <kendo-excelexport-column field="memberName"   title="Patient"  [width]="250">
        <ng-template kendoGridExcelTemplate >Bob Woolmer</ng-template>
    </kendo-excelexport-column>
    <kendo-excelexport-column field="provider" title="Provider" [width]="180">
    </kendo-excelexport-column>
    <kendo-excelexport-column field="status" title="Status" [width]="100">
    </kendo-excelexport-column>
    <kendo-excelexport-column field="patientResponsibility" title="You Owe" width="120"   [cellOptions]="{ format: '$#,##0.00',bold:true }">
    </kendo-excelexport-column>
</kendo-excelexport>

服务日期列始终显示“2017-09-09T00:00:00”而不是 09/09/2017。

有谁知道如何将日期格式化为只有 MM/dd/yyyy 在角剑道网格的 excel 导出中?

【问题讨论】:

  • 你有没有得到这个工作?

标签: excel angular grid export kendo-ui-angular2


【解决方案1】:

不是这个

<kendo-excelexport-column field="dateofService" title="Date(s) of Service" [width]="170"  [cellOptions]="{ format: 'yy-MM-dd hh:mm:ss' }"></kendo-excelexport-column>`

试试这个

<kendo-excelexport-column field="dateofService" title="Date(s) of Service" [width]="170"  [cellOptions]="{ format: 'mm/dd/yyyy' }"></kendo-excelexport-column>

如果您查看 excel 导出 API - CellOptions,它们似乎支持所有 excel 格式选项。

以下链接指定了所有支持的单元格格式选项:Supported Formats

完整的示例代码(也可以在这里查看它的实际操作:Plunker

import { Component } from '@angular/core';
import { products } from './products';

@Component({
    selector: 'my-app',
    template: `
        <button type="button" class="k-button" (click)="save(excelexport)">Export To Excel</button>

        <kendo-excelexport #excelexport [data]="data" [fileName]=downloadFileName>
            <kendo-excelexport-column field="ProductID" title="Product ID" [width]="75">
            </kendo-excelexport-column>
            <kendo-excelexport-column field="ProductName" title="Product Name">
            </kendo-excelexport-column>
            <kendo-excelexport-column field="SomeDate" title="Start Date" [cellOptions]="{ format: 'mm/dd/yyyy' }"></kendo-excelexport-column>
      </kendo-excelexport>
    `
}) 
export class AppComponent {
    public data: any[] = products;
    public downloadFileName: string = "My file.xlsx"

    public save(component): void {

        this.data.forEach((product) => {
          product.SomeDate = new Date();
        });

        setTimeout(
          () => {
            const options = component.workbookOptions();
            component.save(options);
          }, 1000);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 2018-12-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 2014-11-10
    相关资源
    最近更新 更多