Parse Xlsx file to JSON in Cypress - testing

I have some problems with implementing tests for downloading the XLSX file and checking the data inside using cypress.
https://kishorsharma69.wordpress.com/2021/07/06/cypress-data-driven-testing-with-excel-file/
I used this tutorial to do the data here look simple: data used in the tutorial
But in my project I have excel files which looks like this: data used in my project
When I'm using the xlsx file from the tutorial everything works well the JSON file is created properly: json file created from tutorial
But how I can make it with my file? How I can for example start from the 5 line of excel file and just take 5 and 6 lines from excel? Thanks for help :)
Here is code used in my tests:
Then('File is downloaded, parsed to json file and compared', () => {
cy.task('readXlsx', {file: 'cypress/downloads/test.xlsx', sheet: "Sheet1" }).then((rows) => {
rowsLength = rows.length;
cy.writeFile("cypress/fixtures/xlsxData.json", {rows})
Here you can find my index.js file: inde.js file
And the read-xlsx.js file: read-xlsx.js file

Related

Forge CSV Data Adapter - Reference Application Data Visualization

I hope you are all doing well. I've been recently trying to modify the AutoDesk reference application to allow me to create a heat-map with my own sensors data and my own model. However, I have been having difficulties. Has anyone done something similar before? Do you have to create two separate .env files or do you just change both the credentials for the FORGE_ID portion and the CSV portion in the same one?
Thank You, (I attached an example of what it looks like with only the CSV portion change.)
Changed CSV portion
The .env file must be unique as it is loaded by the dotenv package to add all these values as environment variable (NodeJS access these variables with process.env.[VARIABLE_NAME]).
To ensure your .env file is used by dotenv, you must set your ENV to local, if you look at /server/router/index.js, you will find these lines :
if (process.env.ENV == "local") {
require("dotenv").config({
path: __dirname + "/../.env",
});
}
As you are on MacOS you could try this command : export ENV=local && npm run dev to start your server in dev mode.
The CSV portion you showed should work, just put all these lines into your current .env file and you should be able to use your own model AND add your own sensors data.

Using import lib to change which module I want to import

I have a directory and inside of the directory are subdirectories and a python file trying to run other files called Main.py. In each of the subdirectories there will be one file called runner.py with its only function I need to execute is “func”. If I want to use importlib.importmodule how would I go about doing that. As of right now I’m iterating over the directory and using:
filepath = sys.argv\[1\] + "/runner.py"
student_module = importlib.import_module("func", filepath)
But I’m afraid I don’t know how to use it properly as I’m new to python.
In case my words weren’t clear the directory architecture is as follows
Directory
->Main.py
->Subdirectory(1)
->runner.py
->Subdirectory(2)
->runner.py
.
.
.
->Subdirectory(n)
->runner.py
I had tried using the snippet of code above and I was expecting to be able to run the func from the different runner.py files. Unfortunately I’m getting a:
ModuleNotFoundError: No module named ‘func’

Write to file in uwp that has been drag-dropped from explorer

If file is dragged and dropped from file explorer it has FileAttributes.ReadOnly flag for StorageFile.Attributes parameter. In that case using StorageFile api to write to file will give error. How to write to file in this case??
In this case PathIO api can be used to write to file (unless file is a system file). Convert data to write into bytes array and then add following code to write to file:
await PathIO.WriteBytesAsync(file.Path, bytes);
This will write to these files without any error. You don't need any additional permission like broadFileSystemAccess for this.

Replacing one character in a long list of file names

I have a list of image files (jpg, png, etc...) that the dot before the suffix was replaced with # this makes the file unrecognizable to the Android os. In dos, it would be easy. How can I do it in js easily because I've never used js before?
If you're using Node.js, you can use the fs module.
I haven't been able to make time to test a solution, but a naive implementation would look probably like this:
// Import the fs module
const fs = require('fs');
// Read all files in directory
var files = fs.readDirSync('/path/to/images/folder/');
// Loop through the files and rename each file
files.forEach(path => fs.rename(path, path.replace('#', '.')));

nodejs npm libraries to access and modify microsoft word documents

Do you know if it is possible to search specific text like "xAx" into a Microsoft Word file (.doc or .docx) hosted on a website, replace it with some other text input by the user and make the file available for download using nodejs?
Is there a npm library that can do that?
If not it is possible to manipulate a PDF file instead? Please note that I do not want to create the document but manipulate a template file in the server.
Thank you for your help.
There is project https://github.com/open-xml-templating/docxtemplater which serves for replacing {placeholders} in a .docx files.
Also supports loops and images, check out demo (examples) on http://javascript-ninja.fr/docxtemplater/v1/examples/demo.html
If odt is an option (these files are open directly by MS Word besides Open and Libre Office and can be set with extension .doc so end users do not freak out) you can use HTML52PDF.
For example something like the following code will replace a string of text by a link:
require_once 'path/to/CreateDocument.inc';
$doc = new Html52pdf\createDocument(array('template' => 'template.odt'));
$format = '.odt';//.pdf, .doc, .docx, .odt, .rtf
//replace natural text
$doc->replace(array('replace me, please' => array('value' => 'external link')), array('format' => array('','')));
$doc->render('replaced_content' . $format);