Cannot show diacritics in exported CSV file - javascript

I wrote a js code that exported data into .csv table. My problem is that when I open the file Excel cannot show Czech diacritics like č or š. Anyone can help me?
function exportData(){
console.log("Started export to CSV.");
const rows = [
["Procesor" + " " + String(window.localStorage.getItem("CPU"))],
["RAM" + " " + String(window.localStorage.getItem("RAM"))],
["Displej" + " " + String(window.localStorage.getItem("display"))],
["Baterie" + " " + String(window.localStorage.getItem("battery"))],
["Grafická karta" + " " + String(window.localStorage.getItem("GPU"))],
];
let csvContent = "data:text/csv;charset=utf-8,"
+ rows.map(e => e.join(",")).join("\n");
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "parametry.csv");
document.body.appendChild(link); // Required for FF
link.click(); // This will download the data file named "my_data.csv".
}`

On my mac, the UTF-8 CSV gets displayed properly, so this is a bug in Excel.
There's a similar question on SO that might be of interest to you, but here's a summary:
Open Excel
Import the data using Data-->Import External Data --> Import Data
Select the file type of "csv" and browse to your file
In the import wizard change the File_Origin to "65001 UTF" (or choose correct language character identifier)
Change the Delimiter to comma
Select where to import to and Finish
Credit to original answer: Is it possible to force Excel recognize UTF-8 CSV files automatically?

Related

Sending Email with PDF attachment from button in PDF Form

I have been attempting to code a button into my adobe PDF form using an article from quora. The goal is to click a button and it opens an email box with the "to", "subject line", "body" and the "PDF" attaching to the email without having to save the pdf somewhere locally on the clients computer.
These are the three different codes I have found and attempted to use. No matter what I do, I end up getting an "Unterminated String Literal" on line 3 where the body field starts. I have tried adding/removing everything I can think of. ;"'{{:.
Please help if you can! See code below.
var customSubject = this.getField("MyTextField").value;
var mailtoUrl = "mailto:email#email.com?subject=" + Information Form;
this.submitForm({Thank you for your considerate attention to the attached pdf. Let me know if you need anything.; further.
cURL: mailtoUrl, cSubmitAs: "PDF" });
var customSubject = this.getField("MyTextField").value;
var mailtoUrl = "mailto:email#email.com=" + Information Form;
this.submitForm({Thank you for your considerate attention to the attached pdf. Let me know if you need anything.
cURL: mailtoUrl, bPDF:true});
var cToAddr = "email#email.comm"
var cSubLine = "Information Form - " + this.getField(No1LastName) + ", " + this.getField(No2LastName) + "
var cBody = "Please find the attached Information Form. Thank you for your considerate attention to the attached."
this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});
I found that declaring a variable for the email portion worked. I was able to include custom to, cc, subject, and body, as well as attaching the PDF.
var customREmail = this.getField("ReqEmail").value;
var customAEmail = this.getField("AgyEmail").value;
var customAgency = this.getField("Agency").value;
var customLName = this.getField("Lease").value;
var customBAddr = this.getField("BldgAddr").value;
var customBCity = this.getField("BldgCity").value;
var mailtoUrl =
"mailto:XXX#XXX.XXX?cc=" +
customREmail +
"; " +
customAEmail +
"&subject=Compliance%20Request: " +
customAgency +
", " +
customLName +
" - " +
customBAddr +
", " +
customBCity +
"&body=Please review the attached request.%0A%0AThank you,%0A%0A";
this.submitForm({
cURL:mailtoUrl, cSubmitAs:"PDF", bPDF:true
});

Exported Excel from HTML table not opening in google sheets

I had written javascript function to convert HTML table to Excel (done) but when I try to open my exported excel in google sheets it give me response something like this
what changes I need to make in my prototype JS function to resolve this issue
handleexportExcel :function(){
var self = this;
$(".monthly-payments-report-details #paymentExcelReport").unbind('click');
$(".monthly-payments-report-details #paymentExcelReport").click(function(e){
var payment_report_table_html = "<table border='2px'>";
var monthly_payment_report_table = document.getElementById('monthlyPaymentReportTable');
for(index = 0 ; index < monthly_payment_report_table.rows.length-1 ; index++)
{
payment_report_table_html += monthly_payment_report_table.rows[index].innerHTML+"</tr>";
}
payment_report_table_html += "</table>";
var anchor_html_excel = document.createElement('a');
anchor_html_excel.href = 'data:application/vnd.ms-excel' + ', ' + encodeURIComponent(payment_report_table_html);
anchor_html_excel.download = 'Payment Report_' + self.start_date + '_' + self.end_date + '.xls';
anchor_html_excel.click();
})
}
Google Sheets is showing you exactly what you exported.
Just because Excel decides to show an HTML table as a worksheet, doesn't mean the GS developers are obliged to include that functionality.
If you want to export an actual Excel file then use a different method in your js.

FreesWitch speech recognition speechtools.jm Error

i am trying to use freesWitch but headed with this error . can sombody help how i can resolve this ? i do get the xml but it can't parse it accordingly
<result grammar="pizza_order">
<interpretation grammar="pizza_order" confidence="100">
<input mode="speech">delivery</input>
</interpretation>
</result>
the point where i am stuck is , i need to parse xml each attribute and each node but i am unable to use dom parser aswel, the only reference i got was
https://freeswitch.org/confluence/display/FREESWITCH/JavaScript+example+-+XML#JavaScriptexample-XML-Examples
but i almost tried everything but cannot get the data out of that XML , kindly help me to get parse this small XML successfully or any simple logic which doesn't use any parser in javascript will also work , i have this xml in string aswel. Thanks
var input1 = xml.getChild('interpretation');
var input2 = input1.getChild('input');
console_log('info', 'XML newChild attrbute firstattr: ' + input1.getAttribute('grammar'));
var score = input1.getAttribute('confidence');
var child = xml.getChild('result');
var ahsan = xml.serialize();
console_log('info', 'Full XML ::\n' + ahsan + " method=" + input2.data );
console_log("debug", "----XML---> :\n" + body + "\n");
console_log("debug", "----Hit score [" + score + "]/" +
grammar_object.min_score + "/" + grammar_object.confirm_score + "\n");
I think it will solve your problem

Making string content strikethrough in Google Apps

I'm faced with a trivial but not-quick-to-get thing: I need to set the font of a string as a strike-through style.
I've tried search for similar solution on Stackoverflow but it wasn't much instructive and helpful.
What I do have:
var bookingDetails = "\nЗаезд: " + row[0] + "\nВыезд: " + row[1] + "\nНомер: " + "«" + row[2] + "»" + "\nТип размещения: " + row[3] + "\n" + "\nЦена за ночь: " + row[4] + " руб." + "\nВнесённый депозит: " + row[8] + " руб." + "\n" + "\nИмя и фамилия гостя: " + row[5] + "\nМобильный телефон: " + row[6] + "\nЭлектронная почта: " + row[7] + "\n" + "\nПримечание: " + row[11];
I need to make the content of bookingDetails striked out without changing anything in the sheet itself. I tried bookingDetails.setFontLine("line-through") but it didn't help by showing the error of "TypeError: Cannot find function setFontLine in object...".
Please, help me fix it.
Just letting you know that I'm very thankful for your attempt to help me in advance.
UPD № 1: I'm using Google Spreadsheets. If it does make sense.
UPD № 2: If it is not possible to make this strike-through transformation just in the script not explicitly in cells then I should add that bookingDetails is used in the email body to be sent through MailApp.sendEmail. So if it possible to transform the contents of bookigndbetails directly in the message body then let me know how to make it as quick as possible on the example of my script.
Hoping that know my goal is clear.
Here is a function that will set strikethrough the text
function setStrikethrough(range) {
var ss = SpreadsheetApp.getActiveSpreadsheet(); // Get the current spreadsheet.
var sheet = ss.getSheets()[0]; // Select the first sheet.
var cell = sheet.getRange(range); // Use supplied arguments
cell.setFontLine("line-through"); // set strikethrough
}
You can call this method like this (this will set the line style of the given range to 'line-through'):
// specify the range
setStrikethrough("B2:C4");
See https://developers.google.com/apps-script/reference/spreadsheet/

How to get streaming url from online streaming radio station

I've been asked to make unofficial online streaming android application for a certain radio station.
I've experience with streaming in android for certain mp3 or whatever stream.
But I don't know the stream url to provide in mediaPlayer.setDataSource(url).
Is there any way to get the stream url from the ofiicial streaming page for ex. this radio stream?
not that hard,
if you take a look at the page source, you'll see that it uses to stream the audio via shoutcast.
this is the stream url
"StreamUrl": "http://stream.radiotime.com/listen.stream?streamIds=3244651&rti=c051HQVbfRc4FEMbKg5RRVMzRU9KUBw%2fVBZHS0dPF1VIExNzJz0CGQtRcX8OS0o0CUkYRFJDDW8LEVRxGAEOEAcQXko%2bGgwSBBZrV1pQZgQZZxkWCA4L%7e%7e%7e",
which returns a JSON like that:
{
"Streams": [
{
"StreamId": 3244651,
"Reliability": 92,
"Bandwidth": 64,
"HasPlaylist": false,
"MediaType": "MP3",
"Url": "http://mp3hdfm32.hala.jo:8132",
"Type": "Live"
}
]
}
i believe that's the url you need:
http://mp3hdfm32.hala.jo:8132
this is the station WebSite
Edited ZygD's answer for python 3.x.:
import re
import urllib.request
import string
url1 = input("Please enter a URL from Tunein Radio: ");
request = urllib.request.Request(url1);
response = urllib.request.urlopen(request);
raw_file = response.read().decode('utf-8');
API_key = re.findall(r"StreamUrl\":\"(.*?),\"",raw_file);
#print API_key;
#print "The API key is: " + API_key[0];
request2 = urllib.request.Request(str(API_key[0]));
response2 = urllib.request.urlopen(request2);
key_content = response2.read().decode('utf-8');
raw_stream_url = re.findall(r"Url\": \"(.*?)\"",key_content);
bandwidth = re.findall(r"Bandwidth\":(.*?),", key_content);
reliability = re.findall(r"lity\":(.*?),", key_content);
isPlaylist = re.findall(r"HasPlaylist\":(.*?),",key_content);
codec = re.findall(r"MediaType\": \"(.*?)\",", key_content);
tipe = re.findall(r"Type\": \"(.*?)\"", key_content);
total = 0
for element in raw_stream_url:
total = total + 1
i = 0
print ("I found " + str(total) + " streams.");
for element in raw_stream_url:
print ("Stream #" + str(i + 1));
print ("Stream stats:");
print ("Bandwidth: " + str(bandwidth[i]) + " kilobytes per second.");
print ("Reliability: " + str(reliability[i]) + "%");
print ("HasPlaylist: " + str(isPlaylist[i]));
print ("Stream codec: " + str(codec[i]));
print ("This audio stream is " + tipe[i].lower());
print ("Pure streaming URL: " + str(raw_stream_url[i]));
i = i + 1
input("Press enter to close")
The provided answers didn't work for me. I'm adding another answer because this is where I ended up when searching for radio stream urls.
Radio Browser is a searchable site with streaming urls for radio stations around the world:
http://www.radio-browser.info/
Search for a station like FIP, Pinguin Radio or Radio Paradise, then click the save button, which downloads a PLS file that you can open in your radioplayer (Rhythmbox), or you open the file in a text editor and copy the URL to add in Goodvibes.
Shahar's answer was really helpful, but I found it quite tedious to do this all myself, so I made a nifty little Python program:
import re
import urllib2
import string
url1 = raw_input("Please enter a URL from Tunein Radio: ");
open_file = urllib2.urlopen(url1);
raw_file = open_file.read();
API_key = re.findall(r"StreamUrl\":\"(.*?),",raw_file);
#print API_key;
#print "The API key is: " + API_key[0];
use_key = urllib2.urlopen(str(API_key[0]));
key_content = use_key.read();
raw_stream_url = re.findall(r"Url\": \"(.*?)\"",key_content);
bandwidth = re.findall(r"Bandwidth\":(.*?),", key_content);
reliability = re.findall(r"lity\":(.*?),", key_content);
isPlaylist = re.findall(r"HasPlaylist\":(.*?),",key_content);
codec = re.findall(r"MediaType\": \"(.*?)\",", key_content);
tipe = re.findall(r"Type\": \"(.*?)\"", key_content);
total = 0
for element in raw_stream_url:
total = total + 1
i = 0
print "I found " + str(total) + " streams.";
for element in raw_stream_url:
print "Stream #" + str(i + 1);
print "Stream stats:";
print "Bandwidth: " + str(bandwidth[i]) + " kilobytes per second."
print "Reliability: " + str(reliability[i]) + "%"
print "HasPlaylist: " + str(isPlaylist[i]) + "."
print "Stream codec: " + str(codec[i]) + "."
print "This audio stream is " + tipe[i].lower() + "."
print "Pure streaming URL: " + str(raw_stream_url[i]) + ".";
i = i + 1
raw_input("Press enter to close TMUS.")
It's basically Shahar's solution automated.
When you go to a stream url, you get offered a file. feed this file to a parser to extract the contents out of it. the file is (usually) plain text and contains the url to play.

Categories