I have example.xlsx file that contains some data.
I want to show the data in a GUI and I want there is an option to edit the xlsx file in the GUI.
Is there an option to do this? Does someone know anything about it?
I tried to find the xls via the ActiveX control, but I didn't see an option for that :/
I have matlab 2010a and these are my options when I press 'ActiveX control':
thank you :]
You don't need activeX, matlab has the built-in functions, xlswrite and xlsread:
Help File:
xlswrite(filename,A) writes array A to the first worksheet in Excel
file filename, starting at cell A1.
xlswrite(filename,A,sheet) writes to the specified worksheet.
xlswrite(filename,A,range) writes to the rectangular region specified
by range in the first worksheet of the file. Specify range using the
syntax 'C1:C2', where C1 and C2 are two opposing corners that define
the region.
xlswrite(filename,A,sheet,range) writes to the specified sheet and
range.
status = xlswrite(filename,A,sheet,range) returns the completion
status of the write operation: true (logical 1) for success, false
(logical 0) for failure. Inputs sheet and range are optional.
[status,msg] = xlswrite(filename,A,sheet,range) returns any warning or
error message generated by the write operation in structure message.
Inputs sheet and range are optional.
and:
[num,txt,raw] = xlsread(filename) reads data from the first worksheet
in the Microsoft Excel spreadsheet file named filename and returns the
numeric data in array num. Optionally, returns the text fields in cell
array txt, and the unprocessed data (numbers and text) in cell array
raw. If your system does not have Excel for Windows, xlsread operates
in basic import mode, and reads only XLS or XLSX files.
[num,txt,raw] = xlsread(filename,sheet) reads the specified worksheet.
[num,txt,raw] = xlsread(filename,range) reads data from the specified
range of the first worksheet in the file. Specify range using the
syntax 'C1:C2', where C1 and C2 are two opposing corners that define
the region.
[num,txt,raw] = xlsread(filename,sheet,range) reads from the specified
sheet and range.
[num,txt,raw] = xlsread(filename,-1) opens an Excel window to
interactively select data. Supported only on Windows systems with
Excel software.
[num,txt,raw] = xlsread(filename,sheet,range,'basic') reads data from
the spreadsheet in basic mode, the default on systems without Excel
for Windows.
[num,txt,raw,custom] = xlsread(filename,sheet,range,'',functionHandle)
reads from the spreadsheet, executes the function associated with
functionHandle on the data, and returns the final results. Optionally,
returns additional custom output, which is the second output from the
function. xlsread does not change the data stored in the spreadsheet.
Supported only on Windows systems with Excel software.
http://www.mathworks.com/help/techdoc/ref/xlswrite.html
With your choice of user interaction and display style (not sure if you want plots or tables, buttons or sliders) this allows you to interact with xls documents.
Try activeX controls in GUIDE. One of the is Excel control.
Related
I want to use xlsread in MATLAB R2017b to read from an externally supplied data file. Usually, this works fine for me. However, in this case I get data I can't find in the .xls file and I don't know what happened.
Here is screenshot of the .xls:
and here of the corresponding raw from xlsread:
Note that there is data in MATLAB (e.g. 'Report tem...') that cannot be found in Excel, that the columns are in a different order and that their headers also differ.
The data file is from Svenska Kraftnät, the Swedish Transmission System Operator and contains the generation and consumption of electrical energy for a certain year. You can find it here.
I use the following line to import the data in question (I am only interested in the numerical data and the timestamps, but used the raw to try to understand what is going on here):
[num,~,raw] = xlsread('n_fot2013-01-12.xls');
I am sorry if this a bad format for the question or if this is a dupe, but I didn't have a clue how to make this question more general. Please feel free to suggest improvements!
Your workbook has a hidden sheet in it, and it is that sheet that is being read.
To read the visible sheet, specify the sheet name:
[num,~,raw] = xlsread('n_fot2013-01-12.xls','Förb + prod i Sverige');
To view the the hidden sheet, on the Home tab, in the Cells group, click Format > Visibility > Hide & Unhide > Unhide Sheet. Then select the hidden sheet.
There isn't a way to tell xlsread to only read visible sheets, and by default it reads the first sheet (hidden or not).
I have a large number of measurement data in excel files. I need to read and process this data using matlab. The problem I have is that not all excel files contain the same amount of data.
I have tried the following
excel = actxserver('excel.application');
xlswb = excel.Workbook.Open(myFile);
data = xlswb.Sheets.Item(mySheet).get('Range', 'A1', 'L10000').Value;
This "works" as there will not be more than 10000 rows and 8 columns (in my case). However, this is very dirty code and I have to check for each file where the data actually ends.
Is there a way to read a whole sheet (similar to the xlsread function)?
Thanks!
Sheets("SheetName").UsedRange will get you a collection every used cell in that sheet. However, if cell L10000 had data and it was cleared, it will still make part of that collection.
I have a large data set in SPSS (v20) with null values for some observations.
I tried saving as an excel 2007 file, but when I open excel file "#NULL!" appears in cells where values are null. I'm going out of ram when trying to use 'find and replace' function in Excel.
T tried saving as a csv file then I got a space in the cells where values are null.
Could anybody advice on this please?
I typically save as CSV and then in excel save as .xlsx. All missing values are then, as you noted, allocated a space which I accept as representing sysmis values.
When I work with a file that has been saved directly to Excel, (ie many "#NULL" values), I use a VBA macros which does a find/replace row by row. The macro is quicker than doing it all at once as this typically starts to slow to infuriating speeds. The macro is still not as fast as one would want...which is why I go via CSV.
According to the command syntax reference, #NULL! values occur only for system missing values. So to prevent that you need to assign the system missings a value - for that you can use the RECODE command (e.g. RECODE MyVar (SYSMIS = -9)(ELSE = COPY). would work for a number field in which -9 can not be a valid value).
Depending on what you want the value to be when written to the sheet, you can then use the /CELLS=VALUES subcommand on SAVE TRANSLATE to save the assigned missing numeric category (IMO a bad idea for spreadsheets) or you can assign the missing value a VALUE LABELS and use /CELLS=LABELS to save the string label in the cell.
I have a spreadsheet where I can enter a reference number and Excel generates a table based on the data tied to that reference number.
Rather than enter each reference number individually and copy the resulting table manually, is it possible to automatically iterate the process of entering the reference numbers (from an existing list) and exporting the results separately?
My Idea:
I didn't quite understand HOW you need to automatically enter those reference, but a good idea would be writing all the numbers you need in a .txt file, then program a button which loads a msoFileDialogFilePicker to select your file. When the file is selected, you can open it with a New FileSystemObject, read it with ReadLine and filling an array with all the numbers you have written in the .txt file. Then with a forcycle from LBoundto UBoundof that array you can enter those numbers automatically in your Range.
To export everytime your results table (which again I didn't quite understand HOW you want it to be exported), an idea would be a Worksheet Changeevent (if the results table appear in your spreadsheet) in which you can write down some code to copy-paste the results table in a new worksheet and then save it, or make a .pdf of the results table from its area.
The possibilities are really too many to write a single piece of code to show you :)
I have a dll exposed via COM to VBA macros in my Excel workbook. In the dll, the primary function takes as input a bunch of data from various cells in the worksheet, and produces a table of outputs to be displayed elsewhere on the same excel worksheet. I am trying to figure out how to have this function called any time one of the input cells change, populating all the output cells at the same time.
It has come to my attention that a VBA UDF cannot write to the speadsheet calling it (no side-effects)... it can only read from the spreadsheet and return values through the functions primary return value.
Is there a good way to map a large input set to a large output set without having to call the dll separately for each entry in the table?
Yes. If the function returns an array, you can select all the future result cells, enter the formula once,
=TheFunction(a1,b2,c3)
and press Ctrl+Shift+Enter.