
Grafieken maken in Excel met Node.js
- [XLSX JS-bibliotheekinstallatie][3]
- [Grafieken maken in Excel met Node.js][4]
Installatie van XLSX JS-bibliotheek
Deze XLSX JS-bibliotheek kan eenvoudig worden geïnstalleerd zonder enige afhankelijkheid van derden. U kunt het API-pakket echter [downloaden][5] of installeren door de volgende opdrachten uit te voeren:
npm install java
npm install aspose.cells
Grafieken maken in Excel met Node.js
Zodra de API is geïnstalleerd, kunnen we naar de volgende stap gaan. Laten we stappen en het codefragment schrijven om grafieken in Excel te maken met Node.js. U kunt de volgende stappen volgen:
- Maak een instantie van de klasse [Workbook][6].
- De referentie van het eerste werkblad verkrijgen door de methode [get(index)][7] aan te roepen.
- Voorbeeldwaarden aan cellen toevoegen door de methode [putValue][8] aan te roepen.
- Gebruik de methode [add][9] om een grafiek aan het werkblad toe te voegen.
- Ga naar de instantie van het nieuw toegevoegde diagram door de methode [get(index)][10] aan te roepen.
- Roep de methode [setChartDataRange][11] aan om de kaartgegevensbron in te stellen als het bereik “A1:C4”.
- De methode [save][12] slaat het bestand op in XLSX-indeling.
Kopieer en plak de volgende code in uw hoofdbestand:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
var aspose = aspose || {}; aspose.cells = require("aspose.cells"); // Create an instance of the Workbook class var workbook = new aspose.cells.Workbook(); // Obtaining the reference of the first worksheet by calling the get(index) method var worksheet = workbook.getWorksheets().get(0); // Adding sample values to cells by calling the putValue method worksheet.getCells().get("A2").putValue("Category1"); worksheet.getCells().get("A3").putValue("Category2"); worksheet.getCells().get("A4").putValue("Category3"); worksheet.getCells().get("B1").putValue("Column1"); worksheet.getCells().get("B2").putValue(4); worksheet.getCells().get("B3").putValue(20); worksheet.getCells().get("B4").putValue(50); worksheet.getCells().get("C1").putValue("Column2"); worksheet.getCells().get("C2").putValue(50); worksheet.getCells().get("C3").putValue(100); worksheet.getCells().get("C4").putValue(150); // Invoke the add method to add a chart to the worksheet var chartIndex = worksheet.getCharts().add(aspose.cells.ChartType.COLUMN, 5, 0, 15, 5); // Access the instance of the newly added chart by calling the get(index) method var chart = worksheet.getCharts().get(chartIndex); // Call the method to set chart data source as the range "A1:C4" chart.setChartDataRange("A1:C4", true); // The save method will save the file in xlsx format workbook.save( "ColumnChart.xlsx", aspose.cells.SaveFormat.XLSX);
Ontvang een gratis licentie
U kunt gebruikmaken van een [gratis tijdelijke licentie][13] om de API zonder evaluatiebeperkingen uit te proberen.
Opsommen
We kunnen deze blogpost hier beëindigen. We hebben gedemonstreerd hoe u grafieken in Excel kunt maken met behulp van Node.js programmatisch. Daarnaast kunt u naar de [documentatie][14] van deze XLSX JS-bibliotheek navigeren om de andere voorzieningen en methoden te kennen. In de komende dagen zullen we andere blogposts bedenken om programmatisch een draaigrafiek in Excel-bestanden te maken. Bezoek daarom [conholdate.com][15] voor de laatste updates.
Een vraag stellen
U kunt uw vragen of opmerkingen aan ons doorgeven op ons [forum][16].
Veelgestelde vragen
Hoe maak ik een Node.js Excel-spreadsheet? U kunt deze XLSX JS [bibliotheek][2] installeren om spreadsheets programmatisch te maken en te verwerken. Hoe maak ik automatisch Excel-grafieken? Volg deze [link][4] voor meer informatie over het schrijven van het codefragment om grafieken te maken in Excel-bestanden in Node.js.
Zie ook
- [Excel converteren naar Markdown in Node.js][17]
- [Excel converteren naar PNG in Node.js][18] [1]: https://docs.fileformat.com/spreadsheet/xlsx/ [2]: https://products.aspose.com/cells/nodejs-java/ [3]: #XLSX-JS-library-installation- [4]: #How-to-Make-Charts-in-Excel-using-Nodejs [5]: https://releases.aspose.com/cells/nodejs/ [6]: https://reference.aspose.com/cells/nodejs/Workbook [7]: https://reference.aspose.com/cells/nodejs/WorksheetCollection#get [8]: https://reference.aspose.com/cells/nodejs/Range#putValue [9]: https://reference.aspose.com/cells/nodejs/ChartCollection#add [10]: https://reference.aspose.com/cells/nodejs/ChartCollection#get [11]: https://reference.aspose.com/cells/nodejs/Chart#setChartDataRange [12]: https://reference.aspose.com/cells/nodejs/Workbook#save [13]: https://purchase.conholdate.com/temporary-license [14]: https://docs.aspose.com/cells/java/create-pivot-tables-and-pivot-charts/#creating-a-pivot-chart-based-on-the-pivot-table [15]: https://conholdate.com/ [16]: https://forum.conholdate.com/ [17]: https://blog.conholdate.com/nl/total/convert-excel-to-markdown-in-nodejs/ [18]: https://blog.conholdate.com/nl/total/convert-excel-to-png-in-nodejs