Append new columns into Excel

In summary, you can use MATLAB to append new columns into existing excel files without altering the original data. You can also use MATLAB to append new rows to existing excel files. Finally, you can solve the problem using a combination of MATLAB and xlswrite.
  • #1

kelvin490

Gold Member
228
3
I would like to ask how to use MATLAB to append new columns into existing excel file without altering the original data in the file? In my case I don't know the original number of columns and rows in the file and it is inefficient to open the files one by one and check in practice. Another difficulty is that the new columns may have different number of rows to the existing data so that I cannot use the trick of reading in the data, forming a new matrix and replace the data with the new matrix.

I have seen many posts teaching people how to add new rows but adding new column seems quite a different thing since the columns are named by letters instead of numbers.

Thank you.
 
Physics news on Phys.org
  • #3
jedishrfu said:
What about exporting the spreadsheet to a CSV file format and then using a scripting language like awk or python to append data to the end of each line and then reimport the spreadsheet?

and from MATLAB a similar approach:

https://www.mathworks.com/matlabcentral/newsreader/view_thread/274697

and using xlswrite in matlab:

http://www.mathworks.com/matlabcent...y-matlab-matrix-when-i-write-it-to-excel-in-m

Finally I solve it in the following way:

if (step==1)
xlswrite(filename,array,sheetname,'A1'); %Create the file
else

[~,~,Data]=xlsread(filename,sheetname); %read in all the old data

OriCol=size(Data,2); %get the column number of the old data

NewCol=OriCol+1; %the new array is placed right next to the original data

ColLetter=xlcolumnletter(NewCol);

StartCell=[ColLetter,'1'];

xlswrite(filename,array,sheetname,StartCell);

end

The xlcolumnletter function is found here:
http://www.mathworks.com/matlabcentral/answers/54153-dynamic-ranges-using-xlswrite
 

1. What is the process for appending new columns into an Excel spreadsheet?

The process for appending new columns into an Excel spreadsheet is fairly simple. First, you will need to open the spreadsheet and select the column to the right of where you want the new columns to be added. Then, right-click on the column letter and select "Insert" from the drop-down menu. This will create a new column to the left of the selected column. Repeat this process for as many new columns as you want to add.

2. Can I append new columns into Excel without disrupting the existing data?

Yes, you can append new columns into Excel without disrupting the existing data. As mentioned in the previous answer, when you insert a new column, it will be added to the left of the selected column. This means that the existing data in the selected column and all columns to the right will be shifted over to make room for the new column. However, the data itself will not be altered or deleted.

3. Is there a limit to the number of columns I can append into an Excel spreadsheet?

Yes, there is a limit to the number of columns you can append into an Excel spreadsheet. The exact limit may vary depending on the version of Excel you are using, but generally, it is around 16,000 columns. If you need to add more columns, you will need to split your data into multiple spreadsheets or use a different software that can handle a larger number of columns.

4. Can I append data from another Excel spreadsheet into my current one?

Yes, you can append data from another Excel spreadsheet into your current one. This can be done by copying and pasting the data, or by importing the data from another spreadsheet using the "Import Data" function in Excel. However, keep in mind that the data may need to be formatted in a specific way in order for it to be properly appended into your current spreadsheet.

5. Will appending new columns affect any formulas or functions in my Excel spreadsheet?

In most cases, appending new columns into an Excel spreadsheet should not affect any formulas or functions that are already in the spreadsheet. However, if the inserted columns are in close proximity to existing formulas or functions, they may need to be adjusted to account for the new columns. It is always a good idea to double-check your formulas and functions after adding new columns to ensure they are still accurate.

Suggested for: Append new columns into Excel

Replies
2
Views
676
Replies
5
Views
991
Replies
2
Views
2K
Replies
17
Views
3K
Replies
7
Views
2K
Replies
18
Views
5K
Replies
4
Views
446
Replies
1
Views
736
Back
Top