Writing a file client side using Angularjs - angularjs

Can we write an xlsx file on client side using angular js .If it is possible then please provide me the solution.

You could use a library like angular-xlsx or js-xlsx to help you with this process.

You can export data from AngularJS to XLS, XLSX and CSV formats with Alasql library.
For example we want to write a data which we saved in test variable in an XLSX file through click a button. To do this just use following steps:
1- Include following files in your page:
<script src="http://alasql.org/console/alasql.min.js"></script>
<script src="http://alasql.org/console/xlsx.core.min.js"></script>
2- So Then make a function in controller to save the test variable as a xlsx file:
$scope.test = [{a:2,b:8,c:9},{a:0,b:14,c:12},{a:24,b:35,c:76}];
$scope.saveAsXlsx = function () {
alasql('SELECT * INTO XLSX("output.xlsx",{headers:true}) FROM ?',[$scope.test]);
}
So We save the data which we had in variable test into a file which we named it output.xlsx here.
3- The last part is the easiest part. Run the function on click on a button:
<button ng-click="saveAsXlsx()" >Save as XLSX</button>
Above solution is a js library which can be used with jQuery, js and angularJS. If you are looking for something just made for angular then in addition of this solution, you can use ng-csv library. If you want to just have a spreadsheet you can use ng-csv library too. It is very easy but you can't get XLSX, you will get the spreadsheet file with CSV format.

you can create your excel file.
install npm install excel4node
and then use the basic code
// Require library
var xl = require('excel4node');
// Create a new instance of a Workbook class
var wb = new xl.Workbook();
// Add Worksheets to the workbook
var ws = wb.addWorksheet('Sheet 1');
var ws2 = wb.addWorksheet('Sheet 2');
// Create a reusable style
var style = wb.createStyle({
font: {
color: '#FF0800',
size: 12
},
numberFormat: '$#,##0.00; ($#,##0.00); -'
});
// Set value of cell A1 to 100 as a number type styled with paramaters of style
ws.cell(1,1).number(100).style(style);
// Set value of cell B1 to 300 as a number type styled with paramaters of style
ws.cell(1,2).number(200).style(style);
// Set value of cell C1 to a formula styled with paramaters of style
ws.cell(1,3).formula('A1 + B1').style(style);
// Set value of cell A2 to 'string' styled with paramaters of style
ws.cell(2,1).string('string').style(style);
// Set value of cell A3 to true as a boolean type styled with paramaters of style but with an adjustment to the font size.
ws.cell(3,1).bool(true).style(style).style({font: {size: 14}});
wb.write('Excel.xlsx');
here i have added ref link :https://www.npmjs.com/package/excel4node

Related

How to export react JS material-ui table data with pagination into csv, excel and pdf?

I am a new front end developer. I am trying to create buttons on front end which can export material-ui table data with pagination into csv, excel and pdf. Is there any library which I can use to do this?
I have good experience using ExcelJS library which not only supports CSV output, but also Excel and other formats. The API is incredibly easy to use, and it also saves you from figuring out how to escape the characters. ExcelJS should work well if you look into file generation in browser or server-side.
Assuming that you know the source of your table data (an array of objects) there are some libraries that you can use to convert from that array into a pdf, xls. For CSV you could make something like
const rows = [
["name1", "city1", "some other info"],
["name2", "city2", "more info"]
];
let csvContent = "data:text/csv;charset=utf-8,";
rows.forEach(function(rowArray) {
let row = rowArray.join(",");
csvContent += row + "\r\n";
});
Then you only have to "open" your generated file into a new window like
const encodedUri = encodeURI(csvContent);
window.open(encodedUri);

Update excel file using selenium webdriver

In my application, there are two buttons(export & import ). Using the export button I can download an excel file, in that downloaded excel file, there are lots of blanks fields.
I need to upload the same file using import button but if I upload the same file then I can get many mandatory fields validation message because of blank fields. Instead of uploading the same file I have another excel file, in which every blank field are filled.
In the exported file, there is a unique id which is generated in the run time and I have to set the same unique id into another excel file, in which every blank field are filled same as the exported file but unique id is different. otherwise, I will get a validation message.
I want to replace the epricer quote number 8766876 to 4181981 in new import file.
Possibly duplicate of following question :
update excel cell in selenium webdriver
Possible solution from link :
InputStream inp = new FileInputStream("workbook.xls");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(3);
if (cell == null)
cell = row.createCell(3);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("a test");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
You cannot update Excel using Selenium, Selenium is a series of libraries that are used to drive a browser, they cannot interact with Excel documents.
If you want to interact with Excel documents you will need to use a library specifically designed to do that, some options are:
Apache POI
DocX4J
JExcelAPI

How to append an existing delta to the end of current Quill content

I have stored existing Quill content as JSON in a database. I need to append this to the end of the existing Quill content and have been unable to do it so far.
UpdateContents(delta) adds it to the beginning of the current content and I have not been successful in specifying an insertion point.
I can specify where to insert plain text with InsertText. How can I accomplish this with inserting deltas?
I found a "Concat" reference at https://github.com/quilljs/delta#construction-1 that allows me to combine the two deltas. Here's an implementation that works for my purposes:
var Delta = Quill.import('delta');
var passedDelta = new Delta(JSON.parse(passedValue));
var existingDelta = this.get("quill").getContents()
var combinedDelta = existingDelta.concat(passedDelta);
this.get("quill").setContents(combinedDelta)

LineBreak within an excel cell using GemBox Spreadsheet

Is it possible to add a line break within an excel cell using the GemBox Spreadsheet API? For example if you're in Excel you can press Alt+Enter and go to a new line in a cell. I'm having trouble finding a property on the CellStyle class in GemBox that allows this. Is it possible?
Thanks
Yes, it is possible, for example try the following:
var ef = new ExcelFile();
var ws = ef.Worksheets.Add("Sheet1");
ws.Cells["A1"].Value = "Sample";
ws.Cells["A1"].Value += "\n" + "Sample";
ef.Save("Sample.xlsx");
In short, just use the new line character in ExcelCell.Value.
Note that when you're assigning such a value, GemBox.Spreadsheet will automatically set ExcelCell.Style.WrapText property to true.

AngularJS - any way to export xls with dynamic content?

I'm investigating for a client feature and I didn't reach the right answer.
This is quite simple : the user edits a full table with datas ( numbers ), chooses which cells receive the sum of which cells and export it.
In Angular we can keep the calculation and hide it to show the result. But what I would like to do is to keep the calculation active when exporting on xls.
For ex.
Cell1 = 25 Cell2 = 45
Cell3 = 70 (Sum(Cell1,Cell2));
In the XLS file It should keep the Sum() function instead of a "flat" 70.
Am I clear enough ? Does someone know a library that can do this ? or the best process to succeed in this feature ?
Excel files are essentially XML Documents.
However building Excel using plain XML is a crazy job...
You can try using the library (ClosedXML) if you are using .NET. https://closedxml.codeplex.com/
It makes much easir to build Excel files.
var wb = new XLWorkbook();
var ws = wb.AddWorksheet("Sheet1");
ws.Cell("A1").SetValue(1).CellBelow().SetValue(1);
ws.Cell("B1").SetValue(1).CellBelow().SetValue(1);
ws.Cell("C1").FormulaA1 = "\"The total value is: \" & SUM(A1:B2)";
var r = ws.Cell("C1").Value;
Assert.AreEqual("The total value is: 4", r.ToString());
// It also works if you use: ws.Cell("C1").GetString()

Resources