I am very new to programming and am working on an Arduino project to measure wavelengths of light.
I am using the Spectruino 3 and am trying to read in the bytes that it records into an array, convert the array into an integer array and then export that data to excel. Currently I have this:
const int numBytes = 501;
int bytestream[numBytes];
void setup(){
Serial.begin(115200);
}
void loop() {
for(int i=0; i<numBytes; i++){
bytestream[i]=Serial.read();
}
}
My spectrometer currently doesn't work, but this seems to compile. I was just wondering how to convert this bytestream array into an integer array and then export it into Excel.
Excel and other, better spreadsheet programs can load text file based CSV files.
That means you have 2 options:
Convert data to CSV rows in device.
Send text data over serial line and use any serial port program on PC that can receive to file to catch the data.
Open CSV file in Excel or other, better spreadsheet program.
Or
Send raw binary data over serial line and use any serial port program on PC that can receive to file to catch the data.
Convert data to CSV file with your favorite scripting language (like Python).
Open CSV file in Excel or other, better spreadsheet program.
Related
I am using excel dart package to edit my excel file. I need to convert the excel into a list of integer bytes List
var excel;
excel = Excel.decode(bytes)
Is that possible to convert the excel to again bytes (opposite of decoding) ?
There are other packages like syncfusion_flutter_xlsio which have a property to save the workbook as List bytes like this:
List<int> bytes = workbook.saveAsStream();
I don't want to use File system for read/write, Thanks
Well, yes, it's in their tutorial and not very surprising:
final bytes = await excel.encode();
I'm trying to read some information from a .txt file and then store it in a structure, but I don't know how to do it only selecting the words I need.
The .txt is the following
fstream write_messages("C:\\Messages.txt");
A line in the .txt looks like this:
18 [#deniseeee]: hello, how are you? 2016-04-26.23:37:58
So, the thing is that I have a list of strutures
list<Message*> g_messages;
where
struct Message {
static unsigned int s_last_id; // keep track of IDs to assign it automatically
unsigned int id;
string user_name;
string content;
string hour;
Message(const string& a_user_name, const string& a_content) :
user_name(a_user_name), content(a_content), id(++s_last_id), hour(currentDateTime())
{
}
Message(){}
};
I want to read the file so that I can store the number into the id of the list, the word between "[#" and "]:" into the user_name, the next sentence into content and the date into the hour.
How can I do this?
Any help is appreciated
Thank you
The problem is: you are writing this file so it is easy to read by a person, while you should write it so it is easy to load by your program.
You are using spaces to separate your elements, while spaces can very well happen inside those elements.
I would suggest to use a symbol that is not likely to be used in the text, for example the pipe '|'. Also, I would write fixed-size elements first:
18|2016-04-26.23:37:58|deniseeee|hello, how are you?
Then you can read entire line, split it on those pipe symbols and load into your struct fields.
Am using androidplot library to display dynamic/static charts & graphs within my Android app. But now I have to export those charts/graphs into excel formats. AndroidPlot library is not providing any API to export the charts/graphs. Is there anyway to do the same?
Can anybody please help me or let me know some workaround to deal with this issue.
That is not a built-in feature of Androidplot however it should be trivial to write a method to suit your needs. All you would need to do is iterate over the XYSeries and write each x/y value to a file separated by a comma. This gives you a generic CSV formatted file that Excel can open. Whether the values or interleaved in or series, how many series are contained in a single file etc, is up to you. To get you started, here's a simple routine that will convert a single XYSeries to an interleaved CSV string. All that's left to do is write the String to file:
/**
* Converts an XYSeries into CSV "x,y,x,y..." format.
* #param series The series to be converted.
* #return CSV formatted version of series.
*/
String toCsv(XYSeries series) {
StringBuffer output = new StringBuffer();
for(int i = 0; i < series.size(); i++) {
output.append(series.getX(i).toString());
output.append(',');
output.append(series.getY(i)).toString();
}
return output.toString();
}
I've got a problem with data in CSV file to import into Excel.
I've parsed data from a website, and contain line break <br>, I convert this tag into "\n" and write to a CSV file. However, when I import this CSV file into Excel, the line-break display incorrectly. It results new line as a new row instead of a new line in a single cell itself.
Anyone have face this problem before? Really appreciate your suggestion.
Thanks!
Edit: Here the sample to demonstrate my situation
static void TestLine()
{
string sampleData = "日찬양 까페에 올린 충격적인 <br>글코리아타임스";
string formattedData = sampleData.Replace("<br>", "\n");
using (StreamWriter writer = new StreamWriter(#"C:\SampleData.csv", false, Encoding.Unicode))
{
writer.WriteLine(formattedData);
}
}
I want the sampleData displaying in a cell, however, the result happens in 2 cells.
It looks to me like misformated CSV file. To handle this situation correctly, you will need to have a field with line break contained within quotation marks.
UPDATE after the sample:
This works fine:
static void Main(string[] args)
{
string sampleData = "\"日찬양 까페에 올린 충격적인 <br>글코리아타임스\"";
string formattedData = sampleData.Replace("<br>", "\n");
using (StreamWriter writer = new StreamWriter(#"C:\SampleData.csv", false, Encoding.Unicode))
{
writer.WriteLine(formattedData);
}
}
You need to wrap the field in the quotation marks (")
Please take a look at CSV-1203 File Format Specification, in particular the sections on "End-of-Record Marker" and "Field Payload Protection". Hopefully this should give clear guidance on the inner workings of the CSV file format.
i am using c# with http helper and using stream reader to read a text. But When i upload a text file containing this text
"Look exactly what I found on # eBay! Willy Lee LifeLike Chatting Butler Prop Motion Sen"
the space is replced by "�" and used in the code.
Code for reading the text is:-
List<string> list = new List<string>();
StreamReader reader = new StreamReader(filepath);
string text = "";
while ((text = reader.ReadLine()) != null)
{
if (!string.IsNullOrEmpty(text))
{
list.Add(text);
}
}
reader.Close();
return list;
list contains this data-
"Look��exactly�what�I�found�on�#�eBay!�Willy�Lee�LifeLike��Chatting�Butler�Prop�Motion�Sen"
Looks like encoding problem - I have had such text problems, when a text is multibyte encoded and shown in a non-unicode based webpage like a Windows-1252 or CP-125X or such.
Here looks like the same - text looks UTF-8 encoded and is displayed in ansi mode, so here the spaces are "special" spaces like these M$ Word puts sometimes, and the english characters are single byte as is the UTF-8 format (forr all chars below ASCII code 128) and this means they are compatible with ANSI codetable and visible correctly.
Or option 2 if it written in a file, and this text is saved like that, witout BOM in the beginning, the text editor may not understand that the context is unicode and opens it in ansi /regular ascii mode/.
If you give more details from where the data is read and where is saved and opened, I can give more concrete details.