Xlsx-js download file

Xlsx-js download file

xlsx-js download file

Here Mudassar Ahmed Khan has explained with an example, how to download Excel file (XLS and XLSX) using JavaScript. The HTML Table. Get the selected local excel file stream through. npm. Jul 23 Downloading file using ajax and jquery after submitting form data using an example how to read and parse Excel file XLS and XLSX using jQuery. xlsx-js download file

Remarkable: Xlsx-js download file

Php click download href file on client side Motorola turbo flash file download
Plex media server download archive Is downloading a gif legal
Games that work with controller on pc no download Download troy torrent

How to Import/Export Excel Spreadsheets using JavaScript

JavaScript is a versatile platform that allows easy customization of client-side scripting tools. In some applications, it's useful to have some sort of spreadsheet interface that is easy to code and maintain. The SpreadJS client-side JavaScript spreadsheet component, part of the SpreadJS package, is perfect for this.

A JavaScript Export To Excel

You can import and export Excel files, and provide users with an interface to interact with those files -- all in pure JavaScript. In this tutorial, I'll show you how easy it is to add a SpreadJS component to an HTML page and import an Excel file into it.

Try SpreadJS's spreadsheet components

Download the latest version of SpreadJS

Download Now!

Set Up The JavaScript Spreadsheet Project

To start off we can use the SpreadJS files hosted on NPM. To do this, we can install using command line argument. Open up a command prompt and navigate to the location of your application. There, you can install the required files with one command.

In this case, we need the base Spread-Sheets library, Spread-ExcelIO, and jQuery:

npm i @grapecity/spread-sheets @grapecity/spread-excelio jquery

Once those are installed, we can add references to those script and css files in our code:

Then add a script to the page that initializes the gwd.es component, and a div element to contain it (since the SpreadJS spreadsheet component utilizes a canvas, this is necessary to initialize the component):

Add Excel Import Code

We need to create an instance of the client-side ExcelIO component that we can use to actually open the file:

Then we need to add a function to import a file. In this example, we import a local file, but you can do the same thing with a file on a server. If you’re importing a file from a server, you need to reference the location. The following is an example of an input element where the user can enter the location of the file:

Once you have that, you can directly access that value in script code:

The following code for the import function just uses a local file for the "excelUrl" variable:

Regardless of whether you're referencing a file on a server or locally, you'll need to add the following to your script inside the $(document).ready function:

Adding Data To The Excel File

In this tutorial, we import a local file that uses the “Profit loss statement” Excel template.

Now we can use gwd.es script to add another revenue line into this file. Let’s add a button to the page that will do just that:

We can write a function for the click event handler for that button to add a row and copy the style from the previous row in preparation for adding some data. To copy the style, we will need to use the copyTo function and pass in:

  • the origin and destination row and column indices
  • row and column count
  • the CopyToOptions value for style

All of the following script code for adding data and a Sparkline will be contained within this button click event handler. For most of the data, we can use the setValue function. This allows us to set a value in a sheet in Spread by passing in a row index, column index, and value:

Set a SUM formula in column P to match the other rows and set a percentage for column Q:

Lastly, we can copy the formulas from the previous rows to the new row for columns R through AD using the copyTo function again, this time using gwd.esa:

Adding A Sparkline

Now we can add a sparkline to match the other rows of data. To do this, we need to provide a range of cells to get the data from and some settings for the sparkline. In this case, we can specify:

  • the range of cells we just added data to
  • settings to make the sparkline look like the other sparklines in the same column

After that, we call the setSparkline method and specify:

  • a location for the sparkline
  • the location of the data
  • the orientation of the sparkline
  • the type of sparkline
  • the settings we created

If you were to try running the code now, it might seem a little slow because the workbook is repainting every time data is changed and styles are added. To drastically speed it up and increase performance, gwd.es provides the ability to suspend painting and the calculation service. Let’s add the code to suspend both before adding a row and its data, and then resume both after:

Once we add that code, we can open the page in a web browser and see the Excel file load into gwd.es with an added revenue row. Important: Keep in mind that Chrome doesn’t allow you to open local files for security purposes, so you need to use a web browser like Firefox to successfully run this code. Alternatively, if you load a file from a website URL, it should open fine in any browser.

Adding Excel Export Code

Finally, we can add a button to export the file with the added row. To do this, we can use the client-side ExcelIO code built into gwd.es:

That code gets the export file name from an exportFileName input element. We can define it and let users name the file like so:

Then we can add a button that calls this function:

Once you add a revenue row, you can export the file using the Export File button. Make sure to add the FileSaver external library to allow users to save the file where they want:

When the file is successfully exported, you can open it in Excel and see that the file looks like it did when it was imported, except there is now an extra revenue line that we added.

This is just one example of how you can use SpreadJS JavaScript spreadsheets to add data to your Excel files and then export them back to Excel with simple JavaScript code.

Download the sample

In another article series, we demonstrate how to export Excel spreadsheets in other Javascript frameworks:

Try SpreadJS's spreadsheet components

Download the latest version of SpreadJS

Download Now!

Categories: Web

Tags: Excel, Export, html5, javascript, Import, Spread, spreadsheet, SpreadJS, Spreadsheets, gwd.es

Share this:

About the Author

Kevin Ashley

The Product Manager for GrapeCity’s SpreadJS product, Kevin Ashley enjoys trying to solve complex coding problems. After graduating from North Carolina State University with a bachelor's degree in Computer Science, he began his career in the software industry at GrapeCity. In his spare time, you can find Kevin playing guitar, drawing, or developing video games.

Comments

Источник: [gwd.es]

Xlsx-js download file

1 thoughts to “Xlsx-js download file”

Leave a Reply

Your email address will not be published. Required fields are marked *