import excel file and read it using ionic - javascript

i want to upload a excel file and read it using ionic-angular , i try with this code but it doesn't work for ionic app its just work for browser i dont know why ?
i want to read it and get a value from it and it doesn't work in ionic app (android )
if there is any plugin for excel file help me
this is my code
<ion-input #inputFile id="input-file" type="file" (change)="excelRead($event)" multiple></ion-input>
public excelRead(e :any ){
let fileReaded :any ;
fileReaded = e.target.files[0];
let type = e.target.files[0].name.split('.').pop();
console.log(fileReaded.name)
const schema = {
'Material' :{
prop : 'material',
type : String ,
required : false
} ,
'Description' :{
prop : 'description',
type : String ,
required : false
} ,
'Emplacement' :{
prop : 'emplacement',
type : String ,
required : false
} ,
'Physique' :{
prop : 'physique',
type : Number ,
required : false
} ,
'Sap' :{
prop : 'sap',
type : Number ,
required : false
} ,
'Ecart' :{
prop : 'ecart',
type : Number ,
required : false
} ,
'Cagette' :{
prop : 'cagette',
type : String ,
required : false
} ,
};
readXlsxFile(fileReaded, {schema}).then((data) =>{
console.log("message1")
if( data.rows){
for (let i of data.rows){
console.log("message2")
this.inventaireTab.push(i);
}
}
console.log("message3")
console.log(this.inventaireTab)
for (let i = 0; i < this.inventaireTab.length; i++) {
this.quantite.push(this.inventaireTab[i].physique)
}
console.log(this.quantite)
}
)
}
if you have any suggestion help me

You have to use Ionic File Opener Plugin:
https://ionicframework.com/docs/native/file-opener
Use this link for reference as in Plugin Documentation usage you'll find only for PDF: how to open (doc, ppt, xlsx, pdf, jpg ,png) file using ionic native file opener
By this you can open different file formats.

Related

Require a JSON file in Node.js Then Access/Iterate Through It?

I believe the error here lies in how I have my Json structured, but this is what is happening.
I have a Json file that looks something like this (omitting key values to protect information):
{
"services" : [
{
"server" : "info",
"baseURL" : "http://info.info.net",
"controlPanelURL" : "http://infoadmin.info.net",
"paths" : {
"restaurantManagerPath" : "/info",
"transactionManagerPath" : "/info",
"userManagerPath" : "/info",
"recordHistoryPath" : "/info"
}
},
{
"server" : "info",
"baseURL" : "http://info.info.net",
"controlPanelURL" : "http://infoadmin.info.net",
"paths" : {
"restaurantManagerPath" : "/info",
"transactionManagerPath" : "/info",
"userManagerPath" : "/info",
"recordHistoryPath" : "/info"
}
}
]
}
I require this file in my main app.js entry-point like so:
const Data = require("./data.json");
Now, if I console.log(Data), I will be shown this:
Now for my problem. It seems I cannot "access" this as an object even though I know using require() on a Json file automatically parses it. Nor can I loop through it with a for...in loop. Here are some examples. Please ignore the "this.json" file, it is a copy of the actual "data.json" file.
Any info would be much appreciated. Thank you in advance for you input on my probably dumb question.

Store a dataURL in MongoDB to access it via local URL (JS)

So I don't know if my title is clear enough, what I want to do is, in my Meteor App, to have a tool that upload a file into my MongoDB, and output an URL that I could use it for example to display as the src of an
Yet, I create my Collection:
export const Files = new Mongo.Collection('files');
and a addFile function :
export const addFile = (nameArg: String, dataURL: String) => {
Files.insert({
_id: uuid(),
name: nameArg,
url: dataURL
});
console.log("file "+nameArg+" added");
};
Then I use the react-jsonschema-form package to display a file form
<Form
schema={{
type: 'object',
properties: {
file: {
type: 'string',
title: 'Upload an image to get its URI'
}
}
}}
uiSchema={{
file: {
'ui:widget': 'file'
}
}}
onChange={this.onChange}
liveValidate
>
<div />
</Form>
My onChange function :
onChange = (e: { formData: { file: string } }) =>{
const [dataType, nameBis,] = e.formData.file.split(';');
const name = nameBis.split('=')[1];
Promise.resolve().then(addFile(name, e.formData.file));
}
And I'd like to use an address sush as window.location.host+'/file/'+name
to be able to use this image.
I believe it to be possible, but how ?
Thanks for all responses :)
This is very much possible and in a secure way using packages cfs:standard-packages and cfs:filesystem. Frankly speaking, I did not go in depth for your question.
It is a beautiful package. You can read about above here packages in depth.
CODE TO CREATE FILESYSTEM COLLECTION
var imageStore = new FS.Store.FileSystem("YOUR_COLLECTION_NAME");
YOUR_COLLECTION_NAME = new FS.Collection("YOUR_COLLECTION_NAME", {
stores: [imageStore]
});
In Short. The files will be saved at the sibling to bundle/ location at cfs/files/YOUR_COLLECTION_NAME. Information about the file will be saved in the collection cfs.YOUR_COLLECTION_NAME.filerecord and temporary location will be used for internal purpose with collection cfs._tempstore.chunks as below.
If you save any file using above package. The metadata will be saved inside the cfs.YOUR_COLLECTION_NAME.filerecord as below
{
"_id" : "TBmxbsL2cMCM2tEc7",
"original" : {
"name" : "photo.jpg",
"updatedAt" : ISODate("2017-07-06T12:54:50.115Z"),
"size" : 2261,
"type" : "image/jpeg"
},
"uploadedAt" : ISODate("2017-07-08T06:58:32.433Z"),
"copies" : {
"YOUR_COLLECTION_NAME" : {
"name" : "photo.jpg",
"type" : "image/jpeg",
"size" : 2261,
"key" : "YOUR_COLLECTION_NAME-TBmxbsL2cMCM2tEc7-photo.jpg",
"updatedAt" : ISODate("2017-07-08T06:58:32.475Z"),
"createdAt" : ISODate("2017-07-08T06:58:32.475Z")
}
}
}
at Client side, you can get the link to the document file using
YOUR_COLLECTION_NAME.find({"_id" : "TBmxbsL2cMCM2tEc7"}).url();
This url is token based safe link to the file instead of direct location to your server. You can set additional allow/deny settings for download ans stuff just like normal collections. Hope this helps!

Schema for User table with multi strategy sigup

While working on one project faced with problem of storing user information for different passport strategies(local, facebook, twitter).
At the begining my UserSchema had such look:
User = mongoose.Schema(
{
"email" : { type : String , lowercase: true , trim : true , unique : true } ,
"providerId" : { type : String } ,
"providerName" : { type : String } ,
"hashedPassword" : { type : String } ,
"salt" : { type : String } ,
"strategy" : { type : String } ,
"created" : { type : Date , default : new Date().valueOf() } ,
"lastConnected" : { type : Date , default : new Date().valueOf() } ,
"accessToken" : { type : String } ,
"securityToken" : { type : String , default : "" } ,
"roles" : [ { type : String } ]
}
);
But unique email brings problem with emails because two users with twitter stategy will have null email and this leads to error.
I thought about not making email unique but this brings alot( from the first look ) of problems.
One the solutions I see is making different schemas for each strategy but this is very difficalt to maintain.
Is there some other way of solving this issue. What are the best practices?
P.S. I swear I googled but didn't find any solution
It seems like you want to be able to say unique:true and specify allowNulls. This now seems possible, as you can see here: https://stackoverflow.com/a/9693138/1935918

Sencha stores as list data source

I'm having a hard time trying to resolve the following thing. I've a store
Ext.define('aBMin.store.Email', {
extend : 'Ext.data.Store',
requires : ['aBMin.model.Email'],
config : {
autoLoad : true,
model : 'aBMin.model.Email',
remoteFilter : true,
proxy : {
type : 'direct',
extraParams : {
filter : 'unassigned'
},
directFn : ClientemailTable.getListMobile,
config : {
paramsAsHash : true,
reader : {
type : 'json'
,rootProperty : 'result'
,successProperty: 'success'
,totalProperty: 'totalCount'
}
}
}
}
});
and the following json is being loaded to it:
[{"totalCount":8,"result":[],"tid":10,"method":"getListMobile","action":"ClientemailTable","type":"rpc"}]
Everything is being loaded properly except the 'totalCount' property to the store. When I'm trying to retrieve in in the Chrome's console, it prints 'null'.
NOTE: the 'result' property is loaded properly so in this case I'm presenting it as an empty array.
Ext.getStore('Email').getTotalCount()
> null
I use sencha touch 2.0. any ideas how to bing it?

How can include a dot character in enum type name in javascript?

I'm using javascript and have this enumeration:
filterType = { Campaign : 'Campaign', Class : 'Class', Date : 'Date',
DateGeq : 'DateGeq', DateLeq : 'DateLeq',
DateRange : 'DateRange', Status : 'Status' }
I'd like to name it as:
Filter.filterType = { Campaign : 'Campaign', Class : 'Class', Date : 'Date',
DateGeq : 'DateGeq', DateLeq : 'DateLeq',
DateRange : 'DateRange', Status : 'Status' }
The interpreter doesn't like dot character.
Can I add a dot character in enumeration names???
Thanks!!!
You're probably getting an error because you're trying to assign a value to the filterType member on a class called Filter, but Filter is undefined. It'll work if you defined Filter first.
var Filter = {};
To do it all in one line you could write:
var Filter = { filterType: { ... } };
I guess you have "Filter" is undefined.
var Filter ={};
Filter.filterType = {....}
How about doing like this?
Filter={}
Filter.filterType = { Campaign : 'Campaign', Class : 'Class', Date : 'Date',
DateGeq : 'DateGeq', DateLeq : 'DateLeq',
DateRange : 'DateRange', Status : 'Status' }
There are no enumerations in JavaScript. What you have shown here is an object, more specifically, an object literal constructed using JSON notation.
You're second example is attempting to create a filterType property (which is a redundant name, by the way) on an object named Filter. If Filter doesn't exist, it will cause an error (consider it analogous to null.filterType which obviously doesn't make any sense). You must first define Filter.
To define Filter and Filter.filterType in one expression, you can use the following notation:
var Filter = {
filterType: {
Campaign : 'Campaign', Class : 'Class', Date : 'Date',
DateGeq : 'DateGeq', DateLeq : 'DateLeq',
DateRange : 'DateRange', Status : 'Status'
}
};

Categories