Solving MATLAB to Excel Copy Issues

In summary, solving MATLAB to Excel copy issues involves using the appropriate data format and ensuring compatibility between the two programs. This can be achieved by converting the data to a compatible format, using the correct syntax, and utilizing built-in functions or add-ons. Additionally, checking for errors and troubleshooting any problems can help to successfully copy data between MATLAB and Excel.
  • #1
member 428835
Hi PF!

I am trying to copy info from MATLAB to Excel via the following code
Matlab:
filename = 'testdata.xlsx';
A = [12.7 5.02 -98 63.9 0 -.2 56];
xlswrite(filename,A)
but I receive the following warning:
Warning: Could not start Excel server for export.
XLSWRITE will attempt to write file in CSV format.

Whatever though, it still creates a file testdata.csv with the matrix ##A## in the first sheet beginning at cell A1. However, I want to be able to put data in different sheets and at different positions, so I used the following code
Matlab:
filename = 'testdata.xlsx';
A = {12,98; 13,99; 14,97};
sheet = 2;
xlRange = 'E1';
xlswrite(filename,A,sheet,xlRange)
which should store ##A## in sheet 2 beginning at position E1. But when I try to run this I get the following the same warning and matrix ##A## is on the sheet titled "testdata" beginning at position A1. Any ideas how to store multiple pieces of data on different sheets at different beginning cells?

Thanks for your time!
 
Physics news on Phys.org
  • #4
It's been awhile since I have been hands-on with Matlab. We only had text file output, back then. Does the Excel file need to already exist (and have multiple sheets created) for it to work?
 
  • #5
scottdave said:
It's been awhile since I have been hands-on with Matlab. We only had text file output, back then. Does the Excel file need to already exist (and have multiple sheets created) for it to work?
The code I was using creates its own .csv file. Within that I tried to create new sheets but I think since it is a .csv file it won't allow me to save any additional sheet other than the sheet it creates. Sooooo I'm not sure how to proceed.
 
  • #8
joshmccraney said:
but I receive the following warning:
Warning: Could not start Excel server for export.
XLSWRITE will attempt to write file in CSV format.
As far as I can tell, this may mean that Excel is not installed on your computer, or that your computer is a Mac.
 
  • Like
Likes scottdave
  • #9
DrGreg said:
As far as I can tell, this may mean that Excel is not installed on your computer, or that your computer is a Mac.
This makes sense. I have a similar issue on my computer that I use for Quickbooks. I used to have OpenOffice on that machine, rather than Excel. When I wanted to export a report to Excel, it would not let me do it, because Excel was not installed on that machine. I could export to a CSV, though. Once I installed Microsoft Excel on that machine, the feature was available (even though OpenOffice Calc can read and write Excel spreadsheets).
 
  • #10
scottdave said:
This makes sense. I have a similar issue on my computer that I use for Quickbooks. I used to have OpenOffice on that machine, rather than Excel. When I wanted to export a report to Excel, it would not let me do it, because Excel was not installed on that machine. I could export to a CSV, though. Once I installed Microsoft Excel on that machine, the feature was available (even though OpenOffice Calc can read and write Excel spreadsheets).
My guess is that MATLAB can't directly read or write Excel spreadsheets, which are in Microsoft's proprietary format, but it can interface to Excel software (if installed) and get Excel to do the reading and writing.
 
  • Like
Likes scottdave
  • #11
Just a thought, maybe it could be capable of doing the older style .XLS format, but not the newer .XLSX format.
 
  • #12
scottdave said:
Just a thought, maybe it could be capable of doing the older style .XLS format, but not the newer .XLSX format.
I would imagine that would depend on which version of Excel is installed.
 
  • #13
joshmccraney said:
The code I was using creates its own .csv file. Within that I tried to create new sheets but I think since it is a .csv file it won't allow me to save any additional sheet other than the sheet it creates. Sooooo I'm not sure how to proceed.
CSV files don't have a concept of "sheets". They are just plain flat ASCII files. Check if your computer has a good EXCEL by double clicking on the CSV file and see if it opens in EXCEL. MATLAB is trying to open EXCEL and insert data in different sheets. If EXCEL is running, maybe your version of MATLAB is not compatible with your version of EXCEL. Then you will have to install compatible versions.

PS. Also make sure that you don't already have that EXCEL file open in EXCEL. If so, close it and try running the MATLAB program again. But I'm sure that problem would give a different error message.
 
  • Like
Likes jim mcnamara
  • #14
DrGreg said:
My guess is that MATLAB can't directly read or write Excel spreadsheets, which are in Microsoft's proprietary format, but it can interface to Excel software (if installed) and get Excel to do the reading and writing.
Yes that is how MATLAB works, according to this help topic. https://www.mathworks.com/help/matlab/import_export/exporting-to-excel-spreadsheets.html

So if 2007 or later is present, then you can write .XLSX, otherwise it is .XLS; if Excel for Windows is not installed, then it will only write .CSV files.
 
  • #15
Wow lot's of good info here, thanks! To answer a few questions: yes, I have Excel downloaded on my machine but I am using a Mac. It sounds like that may be the issue? Also, when I double click the .CSV file Excel opens it.
 
  • #16
joshmccraney said:
Wow lot's of good info here, thanks! To answer a few questions: yes, I have Excel downloaded on my machine but I am using a Mac. It sounds like that may be the issue? Also, when I double click the .CSV file Excel opens it.
From the way I understood the information, it only works under Windows. I would think that with OpenOffice having filters to read and write Excel spreadsheets, that there would be some open source approach, for people who do not have Microsoft Excel (Windows version).
If you are not trying to create a bunch of sheets in the worksheet, perhaps you could create just multiple .CSV files, then open them in Excel and arrange into one big worksheet there?
 
  • #17
scottdave said:
From the way I understood the information, it only works under Windows. I would think that with OpenOffice having filters to read and write Excel spreadsheets, that there would be some open source approach, for people who do not have Microsoft Excel (Windows version).
If you are not trying to create a bunch of sheets in the worksheet, perhaps you could create just multiple .CSV files, then open them in Excel and arrange into one big worksheet there?
Yea this isn't a bad idea except that I can only seem to copy one matrix per .CSV file; since I can't put matrices where I want (always in Cell A1) all data gets overwrote.
 
  • #18
joshmccraney said:
Yea this isn't a bad idea except that I can only seem to copy one matrix per .CSV file; since I can't put matrices where I want (always in Cell A1) all data gets overwrote.
Are you opening the file in "append" mode? That should allow you to write several things in order.
See https://www.mathworks.com/examples/matlab/mw/matlab-ex30745299-append-to-or-overwrite-existing-text-files

Perhaps you can put a sheet name in the first column of the CSV file rows and sort or filter in EXCEL.
 
  • #19
FactChecker said:
Are you opening the file in "append" mode? That should allow you to write several things in order.
See https://www.mathworks.com/examples/matlab/mw/matlab-ex30745299-append-to-or-overwrite-existing-text-files

Perhaps you can put a sheet name in the first column of the CSV file rows and sort or filter in EXCEL.
I did try this but am still having issues. It's not a huge deal though, for now I can copy/paste into excel. I do have windows machines that I can transfer data to if I really need to. Thanks for all your help though!
 

FAQ: Solving MATLAB to Excel Copy Issues

Why is my MATLAB data not copying properly into Excel?

There could be several reasons for this issue. Check to make sure that your data is in the correct format for Excel, such as being in numerical or textual form. Also, ensure that your data is not exceeding the maximum number of rows or columns allowed in Excel.

How can I fix the formatting of my data when copying from MATLAB to Excel?

You can try adjusting the display format in MATLAB before copying the data. This can be done by using the format command and specifying the desired format, such as 'short' or 'long'. You can also try using the "Paste Special" function in Excel to paste the data as values only, which can help with formatting issues.

My Excel file won't update when I make changes in MATLAB. How can I fix this?

Make sure that you are saving your changes in MATLAB before trying to update the Excel file. Additionally, check that you are referencing the correct file and that there are no errors in your code preventing the update.

How can I copy and paste multiple matrices from MATLAB into separate sheets in Excel?

One way to do this is by using the xlswrite function in MATLAB. This allows you to specify the sheet and range of cells where you want to paste the data. You can also use a for loop in your code to iterate through each matrix and paste it into a different sheet.

Is there a limit to the amount of data I can transfer from MATLAB to Excel?

Yes, there is a limit to the number of rows and columns that can be transferred from MATLAB to Excel. The exact limit may vary depending on your version of Excel, but it is typically around 1 million rows and 16,000 columns. If your data exceeds these limits, you may need to split it into smaller chunks or find an alternative method for transferring the data.

Similar threads

Replies
4
Views
3K
Replies
5
Views
13K
Replies
2
Views
12K
Replies
3
Views
2K
Replies
1
Views
4K
Back
Top