getting error reading the excel file in flutter web - flutter

here is my code it's printing the encrypted data
ht.InputElement File = ht.FileUploadInputElement();
File.click();
File.onChange.listen((event) {
final file = File.files.first;
final reader = ht.FileReader();
var a = file.name;
if(a.contains('.xlsx')) {
reader.onLoadEnd.listen((event) {
var decoder = SpreadsheetDecoder.decodeBytes(reader.result);
var table = decoder.tables['Sheet 1'];
var values = table.rows[0];
print(values);
});
}
output
js_primitives.dart:47 [� [!��Ov�!���%������L�vo���W�F���"�8\��(2z�
I want to print the data at row 0
can anyone help me in this

Okh so I solved it finally just need to add
reader.readAsArrayBuffer(file);
before reader.onLoadEnd

Related

Remove column name after get data

So when I get some string data from database I'm using this method
var res = "";
Future<void> cetak(String query) async {
var req = await SqlConn.readData(query);
setState(() {
res = req;
});
}
then im using method cetak() like this
cetak("SELECT CUST_NAME FROM ts_custxm WHERE CUST_CODE = '$custCode'");
But when im trying to display the res using Text(res)
it show [{"CUST_NAME":"MY NAME"}]
any idea how to make res only show MY NAME without show its column name?
You first need to convert by jsonDecode() or json.decode():
var req = jsonDecode(req)
setState(() {
res = req;
});
and then access to your data by:
res[0]["CUST_NAME"].toString()
You are getting result of a query in res variable. As a result of a query is an array of objects.
in your case : [{"CUST_NAME":"MY NAME"}]
so get MY NAME you should use res[0]["CUST_NAME"].toString().
Hope this will help!

Download a sub stream with youtube_explode_dart

I'm developing a Flutter app, using the package youtube_explode_dart.
Currently I download all the audio stream, then crop it using ffmpeg. Quickly this looks like :
var id = "aboZctrHfK8";
var file = File("mySong.mp4");
var start = "2000ms";
var end = "5000ms";
// Downloading audio only
var manifest = await yt.videos.streamsClient.getManifest(id);
var audio = manifest.audioOnly.first;
var audioStream = yt.videos.streamsClient.get(audio);
var output = file.openWrite(mode: FileMode.writeOnlyAppend);
for (final data in audioStream) {
output.add(data);
}
// Croping audio
FlutterFFmpeg _flutterFFmpeg = new FlutterFFmpeg();
await _flutterFFmpeg.executeWithArguments([
"-v", "error",
"-ss", start,
"-to", end,
"-i", file.path,
"-acodec", "copy", "myCroppedSong.mp4"]);
Now I'm facing another issue: Some videos are really heavy and take a while to download. This is not acceptable for my end users, especially since I only want part of the original audio.
Is there a way to download only a subset of the audio stream?
Something like:
for (final data in audioStream.subset(start, end)) {
output.add(data);
}
It would be anwsome!
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
// Initialize the YoutubeExplode instance.
final yt = YoutubeExplode();
Future<void> ExplodeDown() async {
stdout.writeln('Type the video id or url: ');
var url = stdin.readLineSync()!.trim();
// Save the video to the download directory.
Directory('downloads').createSync();
// Download the video.
await download(url);
yt.close();
exit(0);
}
Future<void> download(String id) async {
// Get video metadata.
var video = await yt.videos.get(id);
// Get the video manifest.
var manifest = await yt.videos.streamsClient.getManifest(id);
var streams = manifest.videoOnly;
// Get the audio track with the highest bitrate.
var audio = streams.first;
var audioStream = yt.videos.streamsClient.get(audio);
// Compose the file name removing the unallowed characters in windows.
var fileName = '${video.title}.${audio.container.name}'
.replaceAll(r'\', '')
.replaceAll('/', '')
.replaceAll('*', '')
.replaceAll('?', '')
.replaceAll('"', '')
.replaceAll('<', '')
.replaceAll('>', '')
.replaceAll('|', '');
var file = File('downloads/$fileName');
// Delete the file if exists.
if (file.existsSync()) {
file.deleteSync();
}
// Open the file in writeAppend.
var output = file.openWrite(mode: FileMode.writeOnlyAppend);
// Track the file download status.
var len = audio.size.totalBytes;
var count = 0;
// Create the message and set the cursor position.
var msg = 'Downloading ${video.title}.${audio.container.name}';
stdout.writeln(msg);
// Listen for data received.
// var progressBar = ProgressBar();
await for (final data in audioStream) {
// Keep track of the current downloaded data.
count += data.length;
// Calculate the current progress.
var progress = ((count / len) * 100).ceil();
print (progress);
// Update the progressbar.
// progressBar.update(progress);
// Write to file.
output.add(data);
}
await output.close();
}
**How to download load youtube video & audio & play stream audio **
String youTubeLink = "https://www.youtube.com/watch?v=Ja-85lFDSEM";
Future<void> _downloadVideo(youTubeLink) async{
final yt = YoutubeExplode();
final video = await yt.videos.get(youTubeLink);
// Get the video manifest.
final manifest = await yt.videos.streamsClient.getManifest(youTubeLink);
final streams = manifest.muxed;
final audio = streams.first;
final audioStream = yt.videos.streamsClient.get(audio);
final fileName = '${video.title}.${audio.container.name.toString()}'
.replaceAll(r'\', '')
.replaceAll('/', '')
.replaceAll('*', '')
.replaceAll('?', '')
.replaceAll('"', '')
.replaceAll('<', '')
.replaceAll('>', '')
.replaceAll('|', '');
final dir = await getApplicationDocumentsDirectory();
final path = dir.path;
final directory = Directory('$path/video/');
await directory.create(recursive: true);
final file = File('$path/video/$fileName');
final output = file.openWrite(mode: FileMode.writeOnlyAppend);
var len = audio.size.totalBytes;
var count = 0;
var msg = 'Downloading ${video.title}.${audio.container.name}';
stdout.writeln(msg);
await for (final data in audioStream){
count += data.length;
var progress = ((count / len) * 100).ceil();
print(progress);
output.add(data);
}
await output.flush();
await output.close();
}

How can I export AgGrid data in case of infinite row model (infinite scrolling) in react

How can I export AgGrid data in case of infinite row model (infinite scrolling) in react.
For the normal row models it is being done in this way:
this.gridOptions.api.exportDataAsCsv(params);
What about infinite row model case?
Here is the solution that I've implemented.
Grid footers, multiple headers is not considered here.
This code is for simple grid with headers and rows under it.
In case of infinite scrolling and dynamic columns (in some cases columns can be changed).
var LINE_SEPARATOR = '\r\n';
var COLUMN_SEPARATOR = ',';
var fileName = 'export.csv';
let csvString = '';
let columnsToExport = this.gridOptions.api.columnController.getAllDisplayedColumns();
// adding column headers.
columnsToExport.map((column) => {
csvString+= column.colDef.headerName;
csvString+= COLUMN_SEPARATOR;
});
csvString+= LINE_SEPARATOR;
// adding content of data currently loaded in the grid.
this.gridOptions.api.forEachNode( function(node) {
node.columnController.allDisplayedColumns.map((column) => {
let cellContent = node.valueService.getValue(column, node);
csvString+= (cellContent != null) ? cellContent : "";
csvString+= COLUMN_SEPARATOR;
});
csvString+= LINE_SEPARATOR;
});
// for Excel, we need \ufeff at the start
var blobObj = new Blob(["\ufeff", csvString], {
type: "text/csv;charset=utf-8;"
});
// Internet Explorer
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blobObj, fileName);
}
else {
// Chrome
var downloadLink = document.createElement("a");
downloadLink.href = window.URL.createObjectURL(blobObj);
downloadLink.download = fileName;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}

How do I retrieve the files from localstorage by the extension name ".log"?

I am new to angular/js/ionic. I have a really quick question.
How do I retrieve data from localstorage when I don't really know the index name? I just want to grab whatever ends with ".log"?
I understand that the code below will try to retrieve the data by the index 'notes'.
var logFile = angular.fromJson(window.localStorage['notes'] || '[]');
var localLogFile = function() {
for(var i = 0; i < localStorage.length; i++) {
var keyName = localStorage.key(i);
var extension = keyName.substring(keyName.lastIndexOf("."));
if(extension == ".log") {
return localStorage.getItem(keyName);
}
}
};
var logFile = angular.fromJson(localLogFile());

get values from XML file in my Titanium Project

I am having the following .xml which i used in my android project.now,am trying to create the same in iPhone using titanium.Can some one tell me how to get this values from the xml file and show them in a table view.? if i give MainCategories the 3 values in it should appear in the table view.Also can some one tell me is there any other better option to achieve this?or can we use plist??thank you.
<string-array name="MainCategories">
<item>Acceleration</item>
<item>Angle</item>
<item>Area</item>
</string-array>
<string-array name="Acceleration_array">
<item>meter/sq sec</item>
<item>km/sq sec</item>
<item>mile/sq sec</item>
<item>yard/sq sec</item>
</string-array>
<string-array name="Angle_array">
<item>degree</item>
<item>radian</item>
<item>grad</item>
<item>gon</item>
</string-array>
Try This.
var result = [];
var fileName = 'arrays1.xml'; //save xml file
var tableView = Ti.UI.createTableView({ data : result, width : '100%', height : '100%' });
function readXML(fileName)
{
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, fileName);
var xmltext = file.read().text;
var doc = Ti.XML.parseString(xmltext);
var parentNodeLength = doc.documentElement.getElementsByTagName('string-array').length;
for (var i = 0; i < parentNodeLength; i++) {
var attrValue = doc.documentElement.getElementsByTagName('string-array').item(i).attributes.getNamedItem('name').nodeValue;
if (attrValue === 'Angle_array') {
var parentNode = doc.documentElement.getElementsByTagName('string-array').item(i);
var subNodeLength = parentNode.getElementsByTagName('item').length;
for (var j = 0; j < subNodeLength; j++) {
var title = parentNode.getElementsByTagName('item').item(j).text;
var row = Ti.UI.createTableViewRow({
height : 110
});
var label = Ti.UI.createLabel({
height : Ti.UI.SIZE,
width : Ti.UI.SIZE,
text : title
});
row.add(label);
result.push(row);
}
}
}
}
readXML(fileName);
tableView.setData(result);
win1.add(tableView);
win1.open();
i am not familiar with titanium but maybe this should help you out:
var result = this.responseText;
var xml = Ti.XML.parseString(result);
var params = xml.documentElement.getElementsByTagName("member");
var name = xml.documentElement.getElementsByTagName("name");
var value = xml.documentElement.getElementsByTagName("string");
var data = [];
for (var i=0;i<params.item.length;i++) {
Ti.API.log('Param '+i+': Name: '+n.item(i).text);
Ti.API.log('Param '+i+': Value: '+v.item(i).text);
// Add to array
data.push({"name":n.item(i).text,"value":v.item(i).text});
}
copied from this link
for displaying it in uitableview, save your values in nsarray and display your array in tableview. here is a tutorial for UITableView.