当前位置:网站首页>For a large amount of data, matlab generates Excel files and typesetting processing source code
For a large amount of data, matlab generates Excel files and typesetting processing source code
2022-07-28 06:20:00 【Tuojiang reed】
#MATLAB Generate EXCEL File and typesetting processing source
Project requirement : Given the tide level data of an ocean station in a year, the tide level data per minute ( Altogether 24×60×365=525600 Number ),txt Format , It is required to make the tide table of the ocean station in that year
Implementation scheme :MATLAB For the txt Document processing , Generate excel workbook , Each worksheet shows the tide level
One Data within days , altogether 365 A worksheet . Each table is 24*60=1440 Data , Abscissa is minutes , The ordinate is hour , Also include longitude and latitude 、 date 、 Time zone and other information
Program implementation function :
1、matlab Generate excel form actxserver(‘excel.application’)
2、matlab Set up excel Column height of cell 、 Line width 、 Horizontal alignment 、 Vertical alignment 、 Cell font size 、 Whether to bold or not , See procedure Cell parameter setting section
3、matlab Realize to excel The merged cells of the table 、 The number of digits displayed in the unified cell (0000 Format ) Wait for the operation See procedure ,NumberFormatLocal=‘0000’
4、 Realize the conversion from current days to date For example 35 God →2019/02/04, See procedure ,datestr()
5、 The transformation from numbers to characters See procedure ,num2str()、cellstr()
[email protected]
%% use A4 Print out the paper
clc
clear
A=load (' Original data of XX port .txt'); % Adjust the data format of tide table per minute
A_1=A(:,5:64);
A_2=zeros(17520,30);
for i=1:8670
A_2(2*i-1,:)=A_1(i,1:30);
A_2(2*i,:)=A_1(i,31:60);
end
AT=load (' High and low tide data of XX port .txt');
AT_1=AT(:,26:33);
chaote=cell(365,8);
for jj=1:365
for kk=1:4
chaote{jj,2*kk-1}=num2str(AT_1(jj,2*kk-1),'%04d');
chaote{jj,2*kk}=num2str(AT_1(jj,2*kk));
end
end
zongriqi=365;
% Table and header , Write the actual value of the table and the abscissa of the header
fenzhong=cell(1,30);
for j=0:29
fen1=num2str(j);fen2=num2str((j+30));
fen=strcat(fen1,'\',fen2);
fenzhong{1,j+1}=fen;
end
for i=1:zongriqi % Every day is a page , Write the actual data and abscissa of the table “ minute ”
B=A_2(48*(i-1)+1:48*i,1:30);
data=num2str(i);
Sheet=strcat('Sheet',data);
xlswrite(' Tide table .xlsx',B,Sheet,'C10:AF57'); % Write the actual data
xlswrite(' Tide table .xlsx',fenzhong,Sheet,'C9:AF9'); % Write the abscissa of the table
end
file_path=[pwd,'\ Tide table .xlsx']; % Set the current path
hExcel=actxserver('excel.application'); % Create a EXCEL The server , And return the handle
set(hExcel,'Visible',1); % Set up Excel The server is visible
hWorkbooks=hExcel.Workbooks.Open(file_path); % Open file
hSheets=hExcel.ActiveWorkBook.Sheets; % Returns the current sheet handle
for k=1:zongriqi % Every day is a page , Write data in the table
hSheetk=hSheets.Item(k); % Back to page k A table handle
hSheetk.Activate; % Activate the form
hSheetk.Range('C1:AF58').ColumnWidth=4; % Set up Range The column width of the object
hSheetk.Range('C1:AF58').RowHeight=25; % Set up Range The row height of the object
hSheetk.Range('C1:AF58').Font.name=' Song style '; % Set cell font size
hSheetk.Range('C1:AF58').Font.size=14; % Set cell font size
hSheetk.Range('C1:AF58').HorizontalAlignment=3; % Set the cell alignment to center horizontally
hSheetk.Range('C1:AF58').VerticalAlignment=2; % Set the cell alignment to center vertically
%hSheetk.Range('C1:AF49').Font.bold=2; % Set the cell font format to bold
hSheetk.Range('C9:AF9').Font.size=9; % Set cell font size
% Header part , Include “ XX port ( chinese 、 English , In the middle )”
hSheetk.Range('A1:AF2').MergeCells=1; % merge cell
hSheetk.Range('A1:AF2').Value=' XX port '; % Write cell contents
hSheetk.Range('A3:AF3').MergeCells=1; % merge cell
hSheetk.Range('A3:AF3').Value='XX_PORT'; % Write cell contents
hSheetk.Range('A1:AF2').Font.name=' Song style '; % Set cell font size
hSheetk.Range('A1:AF2').Font.size=36; % Set cell font size
hSheetk.Range('A3:AF3').Font.size=18; % Set cell font size
hSheetk.Range('A1:AF3').HorizontalAlignment=3; % Set cell alignment , In the middle
hSheetk.Range('A1:AF3').VerticalAlignment=2; % Set cell alignment , In the middle
% Header part , Include “2019 year 1 Moon tide table Longitude and latitude xx′S,xxE” 1 Japan
hSheetk.Range('A4:D4').MergeCells=1; % merge cell
Num=datenum('1-January-2019');
num=Num+k-1;
date_str=datestr(num,'yyyy/mm/dd');
hSheetk.Range('A4:D4').MergeCells=1; % merge cell
hSheetk.Range('A4:D4').Value=date_str; % Write the current date
hSheetk.Range('M4:R4').MergeCells=1; % merge cell
hSheetk.Range('M4:R4').Value=xxS,xx′E'; % Write the current latitude and longitude
hSheetk.Range('A4:D4').Font.name=' Song style '; % Set cell font size
hSheetk.Range('A4:D4').Font.size=22; % Set cell font size
hSheetk.Range('A4:D4').HorizontalAlignment=3; % Set cell alignment , In the middle
hSheetk.Range('A4:D4').VerticalAlignment=2; % Set cell alignment , In the middle
% Header part , Write the ordinate of the table , Hours
for s=1:24
shi1=num2str((2*s+8));shi2=num2str((2*s+9));shi3=num2str((s-1));
shi=strcat('B',shi1,':','B',shi2);
hSheetk.Range(shi).MergeCells=1; % merge cell
hSheetk.Range(shi).Value=shi3; % Write cell contents
end
hSheetk.Range('B10:B57').Font.name=' Song style '; % Set cell font size
hSheetk.Range('B10:B57').Font.size=22; % Set cell font size
hSheetk.Range('B10:B57').Font.bold=2; % Set the cell font format to bold
hSheetk.Range('B10:B57').HorizontalAlignment=3; % Set cell alignment
hSheetk.Range('B10:B57').VerticalAlignment=2; % Set cell alignment
% Header part , The meaning of writing the horizontal and vertical coordinates of the table , Hours \ minute
hSheetk.Range('B8:B9').MergeCells=1; % merge cell
hSheetk.Range('B8:B9').Value='H\M'; % Write cell contents
hSheetk.Range('B8:B9').Font.name=' Song style '; % Set cell font size
hSheetk.Range('B8:B9').Font.size=16; % Set cell font size
hSheetk.Range('B8:B9').Font.bold=2; % Set the cell font format to bold
hSheetk.Range('B8:B9').HorizontalAlignment=3; % Set cell alignment
hSheetk.Range('B8:B9').VerticalAlignment=2; % Set cell alignment
% Header part , The meaning of writing the horizontal and vertical coordinates of the table , Top row 0:29 Every minute , Lower row 30:59 Every minute
hSheetk.Range('C8:AF8').Value=0:1:29; % Write cell contents
hSheetk.Range('C9:AF9').Value=30:1:59; % Write cell contents
hSheetk.Range('C8:AF9').Font.name=' Song style '; % Set cell font size
hSheetk.Range('C8:AF9').Font.size=14; % Set cell font size
hSheetk.Range('C8:AF9').Font.bold=2; % Set the cell font format to bold
hSheetk.Range('C8:AF9').HorizontalAlignment=3; % Set cell alignment
hSheetk.Range('C8:AF9').VerticalAlignment=2; % Set cell alignment
% Header and footer , Thicken the top and bottom borders of the table
hSheetk.Range('B8:AF8').Borders.Item(3).Weight=4; % Set the top border of the table to be bold for line segments
hSheetk.Range('B57:AF57').Borders.Item(4).Weight=4; % Set the bottom border of the table to be bold for line segments
% The end of the table , Write time zone and tide reference
hSheetk.Range('B58:G58').MergeCells=1; % merge cell
hSheetk.Range('B58:G58').Value='Time Zone: -1100'; % Write cell contents
hSheetk.Range('S58:AF58').MergeCells=1; % merge cell
hSheetk.Range('S58:AF58').Value='Tidal high datum: 83cm below average sea level'; % Write cell contents
hSheetk.Range('B58:AF58').Font.name=' Song style '; % Set cell font size
hSheetk.Range('B58:AF58').Font.size=14; % Set cell font size
hSheetk.Range('B58:AF58').Font.bold=2; % Set the cell font format to bold
hSheetk.Range('B58:AF58').RowHeight=35; % Set the row height of the cell
hSheetk.Range('B58:AF58').HorizontalAlignment=3; % Set cell alignment
hSheetk.Range('B58:AF58').VerticalAlignment=2; % Set cell alignment
% Header part , Write the highest tide and the corresponding tide time in the tide table every day
hSheetk.Range('D6:H6').MergeCells=1; % merge cell
hSheetk.Range('D6:H6').Value='Tide time(h:m)'; % Write cell contents , Tide meter
hSheetk.Range('D7:H7').MergeCells=1; % merge cell
hSheetk.Range('D7:H7').Value='Tide height(cm)'; % Write cell contents , Tide gauge
hSheetk.Range('D6:H7').HorizontalAlignment=2; % Set the cell alignment to left
hSheetk.Range('J6:AF7').HorizontalAlignment=4; % Set the cell alignment to right
% Merge cells , Set to align right , Uniform for 4 digit , And write the cell contents ,4 The time corresponding to each tide height ,
hSheetk.Range('J6:K6').MergeCells=1;hSheetk.Range('M6:N6').MergeCells=1;hSheetk.Range('P6:Q6').MergeCells=1; hSheetk.Range('S6:T6').MergeCells=1;
hSheetk.Range('J6:K6').NumberFormatLocal='0000';hSheetk.Range('M6:N6').NumberFormatLocal='0000';% The format is unified as 4 digit
hSheetk.Range('P6:Q6').NumberFormatLocal='0000';hSheetk.Range('S6:T6').NumberFormatLocal='0000';% The format is unified as 4 digit
hSheetk.Range('J6:K6').Value=cellstr(chaote{k,1});hSheetk.Range('M6:N6').Value=num2str(chaote{k,3},'%04d'); % Write tide
hSheetk.Range('P6:Q6').Value=num2str(chaote{k,5},'%04d');hSheetk.Range('S6:T6').Value=num2str(chaote{k,7},'%04d'); % Write tide
% Merge cells , Set to align right , And write the cell contents ,4 The tide is high
hSheetk.Range('J7:K7').MergeCells=1;hSheetk.Range('M7:N7').MergeCells=1;hSheetk.Range('P7:Q7').MergeCells=1; hSheetk.Range('S7:T7').MergeCells=1;
hSheetk.Range('J7:K7').Value=num2str(chaote{k,2});hSheetk.Range('M7:N7').Value=num2str(chaote{k,4});% Write tide height
hSheetk.Range('P7:Q7').Value=num2str(chaote{k,6});hSheetk.Range('S7:T7').Value=num2str(chaote{k,8});% Write tide height
hSheetk.Range('D6:AF7').Font.name=' Song style '; % Set cell font size
hSheetk.Range('D6:H7').Font.size=14; % Set cell font size , Header size
hSheetk.Range('D6:H7').Font.bold=2; % Set the cell font format to bold , Bold the header
hSheetk.Range('J6:AF7').Font.size=20; % Set cell font size , Tide height and tide time
end
Quit(hExcel);
delete(hExcel);
Insert a code chip here
边栏推荐
- A NOVEL DEEP PARALLEL TIME-SERIES RELATION NETWORK FOR FAULT DIAGNOSIS
- 1、 Speech synthesis and autoregressive model
- 浅谈FLUKE光缆认证?何为CFP?何为OFP?
- (PHP graduation project) based on PHP online travel website management system to obtain
- vSphere ESXi 7.0 Update 3 发行说明
- TCL and eltcl? Cdnext and CMRL?
- Never leave its origin - bluecms1.6 vulnerability of the controller's shooting range
- 《On Low-Resolution Face Recognition in the Wild:Comparisons and New Techniques》低分辨率人脸识别论文解读
- 关于gcc :multiple definition of
- 压敏电阻设计参数及经典电路记录 硬件学习笔记5
猜你喜欢

1、 Speech synthesis and autoregressive model

FLUKE福禄克Aircheck wifi测试仪无法配置文件?---终极解决心得

深度学习(二)走进机器学习与深度学习编程部分

用于快速低分辨率人脸识别模型训练的改进知识蒸馏《Improved Knowledge Distillation for Training Fast LR_FR》

Geek challenge 2019-sql injection five questions PW

The difference and relation between TCP and UDP

《On Low-Resolution Face Recognition in the Wild:Comparisons and New Techniques》低分辨率人脸识别论文解读

(PHP graduation project) based on PHP online travel website management system to obtain

ESXi Arm Edition version 1.10更新

Interpreting the knowledge in a neural network
随机推荐
Tornado first met
TVS管参数与选型
arduino 读取模拟电压_MQ2气体/烟雾传感器如何工作及其与Arduino接口
PLC的整体认识
针对大量数据,MATLAB生成EXCEL文件并进行排版处理的源码
TCL and eltcl? Cdnext and CMRL?
2、 Openvino brief introduction and construction process
1、 Speech synthesis and autoregressive model
二、OpenVINO简述与构建流程
GF(2^8)的加法与乘法计算
三极管设计,理解饱和,线性区域和截止区
Which enterprises are suitable for small program production and small program development?
Model inversion attacks that exploit confidence information on and basic countermeasures
浅谈FLUKE光缆认证?何为CFP?何为OFP?
What are the general wechat applet development languages?
压敏电阻设计参数及经典电路记录 硬件学习笔记5
WebService出错 Maximum message size quota for incoming messages (65536) has been exceeded.已超过传入消息(655
Fluke fluke aircheck WiFi tester cannot configure file--- Ultimate solution experience
Cyclic neural network
机群作业管理系统,求解答进程方面的疑问