I have a script in casperJS that scrapes data from a webpage, then puts that information into a variable
var lbdes = casper.fetchText(x('//*[#id="product_overview"]'));
and I call that variable using FS to create an excel doc.
casper.then(function() {
var f = fs.open('scrapetest.xls', 'w');
f.write(lbdes);
f.close();
});
Problem is, when that variable imports into excel it looks like the image below -- Ideally I would love to keep that formatting but somehow force that string to stay in 1 cell rather than spanning across 3+ rows and 3+ columns.
Related
I would like to insert a data to a cell in excel using nodejs. Can someone help me do the same nodejs. I have to read an excel file from my nodejs code and insert data to aparticular cell of my excel sheet.
I tried a code in which the below code gives the output as shown after that how can I acess that data in v ie, john
code snippet
console.log(JSON.stringify(worksheet['A2']))
output
{"t":"s","v":"john","r":"<t>jon</t>","h":"john","w":"jon"}
fullcode - itried to insert a data to a cell of excel
const XLS
X = require('xlsx');
let workbook = XLSX.readFile('test1.xlsx');
let sheetName = workbook.SheetNames[0];
console.log(sheetName+' sheetName')
let worksheet = workbook.Sheets[sheetName];
console.log(worksheet['A2']+' worksheet a2')
console.log(JSON.stringify(worksheet['A2']))
worksheet['A2'].value = 'test';
var cell = worksheet.getCell('A2');
//cell.value = 'test';
sheetName.getCell("A2").value = "test"
If you're familiar with how Pandas DataFrames are structured (basically an array of key-value pairs, with the keys being the column names), then convert-excel-to-json is probably a good bet for what you're looking for. It's fairly straightforward to set-up, and should let you traverse the converted sheet and edit it, as a JSON object. Post this, you can go back to the excel file-format, using something like json2xls.
const result = excelToJson({
sourceFile: 'SOME-EXCEL-FILE.xlsx'
});
result.sheet1[0]["Col_Name"] = "Foo"
However, this may not be feasible for extremely large excel sheets, especially if it becomes inconvenient to hold the entire contents in memory. If this is the case, then copying the sheet data over line-by-line, and modifying the required row would probably be the way to go. I'm going to draw this answer to a close here because I'm not sure if that's what you're looking for, but if it is, I'd be glad to help out with that :)
I have a spreadsheet that has information entered by multiple people on multiple devices and different font settings. I would like a simple script to change all pages of the spreadsheet, (3 on test but actually 5 pages on original). Preferably on any edit, but when you switch from page to page within the sheet would be fine.
Here is link to spreadsheet:-
https://docs.google.com/spreadsheets/d/1hUSgX4Teg71sgI6AUlxgY7HCatUTAszP3M4f6o_eyMU/edit?usp=sharing
My script below:-
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets();
var cell = sheet.getRange("C6:P26");
cell.setFontSize(12);
cell.setHorizontalAlignment("center");
}
I have tried onEdit too but still not working but debugger is not throwing up errors just not running. Not sure if it is the Range option as it doesn't select the correct area in each sheet, should I make 1 per sheet?
Here is the working code after many tries.
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets();
var cell = ss.getRange("C6:U39");
cell.setFontSize(12);
cell.setHorizontalAlignment("center");
}
I want to write a program that is able to read a specific range of numerous excel files in a folder.
because I need MATLAB to read from several excel files, I can't use a coding like this :
xlsread('Report1',1,'k41')
Is it possible to modify below codes in a way to be able to read 'K41' cellular from each excel file?
clc
clear all
Folder = 'D:\Program Files\MATLAB\R2013a\bin';
XLfiles = dir(fullfile(Folder, '*.xlsx'));
for i = 1:length(XLfiles)
data = xlsread(fullfile(Folder, XLfiles(i).name));
end
As excaza said, xlsread should work, just check the 'range' parameter from xlsread, needs to be a string in this format (this is to import only C1).
'C1:C2'
If you use K41:K41 it imports nothing, as it is a 0 range. Maybe that is the confusion here.
See if this might work
all_cells = []; %store all your cells in here
Folder = 'D:\Program Files\MATLAB\R2013a\bin';
XLfiles = dir(fullfile(Folder, '*.xlsx'));
for i = 1:length(XLfiles)
all_cells (end+1)= xlsread(fullfile(Folder, XLfiles(i).name), 'K41:K42');
end
I want to parse an xlsx file which contains hyperlinks on my node.js server.
I tried some xlsx parser in npm (like 'excel-parser', 'xlsx'), but I couldn't get the hyperlink values (only the text value).
Does anyone knows how to extract the hyperlink using node.js ?
If you dislike the existing solutions, you can always unzip the file (OfficeOpen XML files are zipped directories with sereval files in it), and parse the main part yourself in the search of links.
An old question, but one without an answer that I could easily find elsewhere after half an hour of looking.
The below code will read an XSLX and dump it to the console row by row: row.values will be plain text or an object with keys formula and result, the former being the hyperlink, the latter the visible text.
I've only just found exceljs so ymmv, but it seems straightforward and has a large, but not overwhelming, variety of options for getting the job done quickly.
const xl = require('exceljs');
const csvPath = 'NTA Transcripts.xlsx';
const workbook = new xl.Workbook();
await workbook.xlsx.readFile(csvPath);
const worksheet = workbook.getWorksheet(1);
worksheet.eachRow({ includeEmpty: true }, (row, rowNumber) => {
console.log("Row ", rowNumber, ": ", JSON.stringify(row.values, null, 2));
});
I'm trying to write a script that passes information from a Google Spreadsheet, compiles it into a CSV file and emails that file.
My problem: The CSV file on my Excel file looks very different that of my Google Spreadsheet (Dead link).
This is what my Excel file looks like, pasted into another Google Spreadsheet.
The code I am using is below:
function myFunction() {
//get active sheet, the last row where data has been entered, define the range and use that range to get the values (called data)
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow=sheet.getLastRow();
var range = sheet.getRange(1,1,lastRow,91);
var data = range.getValues();
//define a string called csv
var csv = "";
//run for loop through the data and join the values together separated by a comma
for (var i = 0; i < data.length; ++i) {
csv += data[i].join(",") + "\r\n";
}
var csvFiles = [{fileName:"example.csv", content:csv}];
MailApp.sendEmail(Session.getUser().getEmail(), "New Journey Information", "", {attachments: csvFiles});
}
You need to ensure that individual cells' data is atomic. For instance, what you see as a time on the sheet contains a Date object when read by your script, then when that's written to a CSV it may be converted to a date & time string with commas, depending on your locale. (Jan 4, 2013 14:34 for example.) To be safe with punctuation that may be interpreted as delimiters by Excel, you should enclose each element with quotes.
No need to modify your code, as this problem has been solved in one of the examples provided in the Docslist Tutorial. So an easy solution is to replace your code.
Change the first bit of the provided saveAsCSV() as follows, and it will operate either with user input or by passing a filename as a parameter.
function saveAsCSV(filename) {
// Prompts the user for the file name, if filename parameter not provided
fileName = filename || Browser.inputBox("Save CSV file as (e.g. myCSVFile):");
...