write data to excel sheet column

15 ビュー (過去 30 日間)
Lalit Patil
Lalit Patil 2012 年 10 月 3 日
Hi, I have certain data. I want to write this data into excel sheet columns into incremental order.. like first data will be written in 'A' column, second data to 'B' column.. third data to 'C' column.. and so on.. so how can i do this... please suggest code or method..

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 3 日
編集済み: Azzi Abdelmalek 2012 年 10 月 3 日
A = {1,2,3,4}; B = {1,3,4}; C = {2,5,3,7,6}
n=max([length(A),length(B),length(C)])
R=cell(3,5)
R(1,1:length(A))=A
R(2,1:length(B))=B
R(3,1:length(C))=C
xlswrite('filename.xls',R')
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 3 日
編集済み: Azzi Abdelmalek 2012 年 10 月 3 日
I think there is a way, just ask your question. If it's not me who can answer, someone else can do.
Walter Roberson
Walter Roberson 2012 年 10 月 4 日
Whether you can create a loop to make the code short depends on the representation of the data you want to store.

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

その他の回答 (1 件)

Yufei Cao
Yufei Cao 2020 年 8 月 18 日
After 8 years, is there a way to do this if the column number is bigger than z?
  2 件のコメント
Eric Dauenhauer
Eric Dauenhauer 2021 年 11 月 25 日
I'm not sure if anyone still needs a solution to this, but I recently had to address the same issue. I'm sure there's a more eleganent way to do this, but this is where I ended up.
The cycle_number is the column number in which you want to "target" (i.e. 1, 2, 3,...26, 27, 28,...52, 53,...), and the target_column is the string output that corresponds to that column number ('A', 'B', 'C',...'Z', 'AA', 'AB', 'AC',...'AZ', 'BA',...), respectively.
function [target_column] = increment_column(cycle_number)
alphabet = [ 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z'];
if cycle_number <= 26
target_column = strcat(alphabet(cycle_number));
else
m = fix(cycle_number/26);
n = (cycle_number - m*26);
if n == 0
m = m - 1;
n = 26;
end
target_column = strcat(alphabet(m), alphabet(n));
end
Miguel Monserrat Diaz
Miguel Monserrat Diaz 2023 年 5 月 29 日
Thank you very much. This is usefull.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by