How to change number format in excel two times via Matlab actxserver?

조회 수: 4 (최근 30일)
Savva Cherdantsev
Savva Cherdantsev 2017년 9월 5일
편집: Savva Cherdantsev 2017년 9월 5일
Hello all,
I have an issue with actxserver(Excel Application), which I can not understand.
Originally, I have an excel file, which includes a column with dates (Format: yyyy-mm-dd). I need to change the format of dates into Number Format (0.00) or General Format, then do some stuff with the other data and finally change back the format into Dates Format (yyyy-mm-dd). So that, after Matlab script runs, my excel file looks unchanged (Date Format). My code:
e=actxserver('excel.application');
eW=e.Workbooks;
filename=[pwd '\testing.xls'];
eF=eW.Open(filename); % open testing.xls
eS=eF.ActiveSheet;
% edit sheet
eS.Range('A2:A12').NumberFormat="0.00";
eS.Range('A2:A12').NumberFormat="yyyy-mm-dd;@";
eF.Save
eF.Close; % close the file
e.Quit;
The Problem
If you run this code, you will see that code changes Range('A2:A12') to "0.00" Number Format:
eS.Range('A2:A12').NumberFormat="0.00";
But for some reason it does not want to change Range('A2:A12') back to "yyyy-mm-dd;@" Date Format:
eS.Range('A2:A12').NumberFormat="yyyy-mm-dd;@";
Thank You.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by