Articles in this section
Category / Section

How to custom print the multiple cell range in Spreadsheet

2 mins read

Description

This knowledge base explains how to custom print the multiple cell range in Spreadsheet.

Solution

It can be achieved by using ‘customPrintSelection()’ extension method which is provided in the extension script (Custom-print-extension.min.js).

 

HTML

 

<script type="text/javascript" src="ej.web.all.min.js"></script>
<script src="Custom-print-extension.min.js" type="text/javascript"></script>
 
<input type="button" onclick="customPrintFunc()" value="Click here to Print" />
<div id="Spreadsheet"></div>

 

JS

 

var defaultData = [{ "Name": "VINET", "Average": 90, "Grade": "S" }, { "Name": "TOMSP", "Average": 83, "Grade": "A" }, { "Name": "HANAR", "Average": 80, "Grade": "A" }, { "Name": "VICTE", "Average": 93, "Grade": "S" }];
 
$("#Spreadsheet").ejSpreadsheet({
    sheets: [{
        dataSource: defaultData
    }],
    loadComplete: "loadComplete"
});

 

RAZOR

 

@(Html.EJ().Spreadsheet<object>("Spreadsheet")
    .Sheets(sheets =>
    {
        <!-- you can define the datasource at server side -->
        sheets.Datasource((IEnumerable)ViewBag.DataSource).Add();
    })
    .ClientSideEvents(
        events => events.LoadComplete("loadComplete")
    )
)

 

ASPX

 

<ej:Spreadsheet ID="Spreadsheet" runat="server">
    <Sheets>
        <ej:Sheet></ej:Sheet><!-- you can define datasource at server side -->
    </Sheets>
    <ClientSideEvents LoadComplete="loadComplete" />
</ej:Spreadsheet>

 

JS

 

function loadComplete(args) {
    //Here extend the ejSpreadsheet.Extension
    $.extend(this, ej.spreadsheetFeatures.extension);
 
    if (!this.isImport) {
        this.setWidthToColumns([{ colIndex: 0, width: 90 }, { colIndex: 1, width: 85 }, { colIndex: 2, width: 100 }, { colIndex: 11, width: 70 }]);
        this.XLChart.createChart("A1:B6", { type: "column", enable3D: false, marker: false, top: 40, left: 260, width: 340, height: 250 });
    }
}
 
function customPrintFunc() {
    var ssObj = $("#Spreadsheet").data("ejSpreadsheet");
 
    //If passed the chart date range, it'll will print chart after its cell data
    ssObj.customPrintSelection(["A1:C10", "A10:C13"]); //Here pass the cells ranges that you want to print.
}

 

 

You can download the custom script ‘custom-print-extension.min.js’ from below link,

 

Custom-print-extension

 

The following screenshot is displayed as the output of custom printing Spreadsheet with chart and its range data.

 

spreadsheet custom print sample preview

Figure:  Custom printing of Chart and its data range in Spreadsheet

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied