use xlswrite to paste the content on a specific cell name

3 ビュー (過去 30 日間)
Luca Tognetti
Luca Tognetti 2022 年 12 月 7 日
コメント済み: Image Analyst 2022 年 12 月 7 日
Hi, i'm using xlsread and xlswrite to copy some cells from one excel file to another.
my problem is that I have the cells in the destination file that have a specific name, for exemple cell A2 is named "volume".
when I use xlsread or xlswrite I don't know how to specify the cell name instead of the cell number. Do I have to use a particular grammar?

採用された回答

Image Analyst
Image Analyst 2022 年 12 月 7 日
No, you can just use "A2" as the range when you use xlswrite or writematrix or writetable. It will write the value that you tell it into that cell. It does not matter the cell is named, or that any range of cells has a name. I believe it will ignore it. If you have an existing workbook where you have named certain cells or ranges of cells, I think writing to the cells will just overwrite the values and not do anything with the existing names you assigned to those cell ranges. But you can easily check that yourself.
  2 件のコメント
Luca Tognetti
Luca Tognetti 2022 年 12 月 7 日
no, I need to find the cell called in a certain way and write in it. for example if a cell is called "volume" and in sheet1 is in position A1 and in sheet2 is in position C3 i would like that just typing "volume" into xlswrite write the value in the right cell. (of course by telling to matlab to change sheet)
Image Analyst
Image Analyst 2022 年 12 月 7 日
Oh, sorry - terminology problem. You don't want to know if a cell is "named" or called something, as Excel uses the term "name". You want to check the value of the cell to see if it's "volume". Well one way is just a simple brute force check in a loop, though perhaps you could figure out how to do it with ismember().
[~, ~, raw] = xlsread(fileName);
[rows, columns] = size(raw)
numOccurrences = 0;
for col = 1 : columns
for row = 1 : rows
thisCell = raw{row, col};
% See if this cell contains the desired string.
if contains(thisCell, 'volume', 'IgnoreCase', true)
% The cell contains the value "volume" as all or part of the cell.
% Increment the count. There may be more than one occurrence so let's just be robust and general
numOccurrences = numOccurrences + 1;
% Record the row and column where it occurs.
volumeRow(numOccurrences) = row;
volumeCol(numOccurrences) = col;
end
end
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by