0

I am generating an Excel file using AngularJS.

The page styling format is working fine, but I need help to set the page property of print area and orientation landscape.

Code:

var mystyle = {
        sheetid: 'Sheet1',
        headers: false,
        style: 'background:none',
        columns: [{
            columnid: 'PRODUCT',
            width: 140,
            wraptext: true
        },
        {
            columnid: 'DESCRIPTION',
            width: 400,
            wraptext: true
        }, {
            columnid: 'QTY',
            width: 40,
            wraptext: true
        },
         {
             columnid: 'LIST_PRICE',
             width: 80,
             wraptext: true
         },
          {
              columnid: 'DISC_PRICE',
              width: 80,
              wraptext: true
          },
           {
               columnid: 'EXT_PRICE',
               width: 80,
               wraptext: true
           },
            {
                columnid: 'OPTIONS',
                wraptext: true,
                width: 500,
            }

        ],
        row: {
            style: function (sheet, row, rowidx) {
                row.QTY = row.QTY != '' ? (Number(row.QTY)) : '';
                row.LIST_PRICE = row.LIST_PRICE != '' ?(parseFloat(row.LIST_PRICE)): '';
                row.DISC_PRICE = row.DISC_PRICE != '' ? row.DISC_PRICE == 'Total' ? row.DISC_PRICE : (parseFloat(row.DISC_PRICE)) : '';
                row.EXT_PRICE = row.EXT_PRICE != '' ? (parseFloat(row.EXT_PRICE)) : '';
                return 'font-weight:' + (row.QTY == '' ? 'bold' : 'none');
            }
        },
        rows: {
            7: { style: { Font: { Bold: 1 } } },
            1: { style: { Font: { Bold: 1 } } },
            2: { style: { Font: { Bold: 1 } } },
            3: { style: { Font: { Bold: 1 } } },
            7: { style: 'font-weight: bold;' }
        },
        cells: {
            1: {
                1: {
                    style: 'font-weight: bold;font-size:15px;'//,
                   // value: function (value) { return value.substr(1, 5); }
                }
            },
            2: {
                1: {
                    style: 'font-weight: bold;font-size:15px;'//,
                    // value: function (value) { return value.substr(1, 5); }
                }
            },
            3: {
                1: {
                    style: 'font-weight: bold;font-size:15px;'//,
                    // value: function (value) { return value.substr(1, 5); }
                }
            },
            7: {
                0: {
                    style: 'border-bottom: 5px solid black;'
                },
                1: {
                    style: 'border-bottom: 5px solid black;'
                },
                2: {
                    style: 'border-bottom: 5px solid black;text-align:right'
                },
                3: {
                    style: 'border-bottom: 5px solid black;text-align:right;'
                },
                4: {
                    style: 'border-bottom: 5px solid black;text-align:right;'
                },
                5: {
                    style: 'border-bottom: 5px solid black;text-align:right;'
                }

            }
        }
    };
    var GetExcelData = SaveOrderService.ExportToExcel(quoteType, $scope.comments);
    GetExcelData.then(function (data) {
        $scope.items = [];
        $scope.items = data.data;
        alasql('SELECT * INTO XLS("'+$scope.excelfilename+'",?) FROM ?', [mystyle, $scope.items]);
    });


};
Graham
  • 7,431
  • 18
  • 59
  • 84
Shaan
  • 1
  • 3

1 Answers1

0

When you generate an Excel file like this you're really only generating html formats that Excel imports on the fly, and not an actual Excel file. Therefore, advanced formatting such as print preferences, data filters, and Excel charting won't be available to you.

In order to do what you want you will have to use a library such as Apache POI on your server.

Graham
  • 7,431
  • 18
  • 59
  • 84