当前位置:网站首页>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
边栏推荐
- 二、OpenVINO简述与构建流程
- Addition and multiplication calculation of GF (2^8)
- USB Network Native Driver for ESXi更新到支持ESXi7.0 Update 2
- Getting started with latex
- Reversible digital watermarking method based on histogram modification
- Web滚动字幕(MARQUEE示例)
- 《Distilling the Knowledge in a Neural Network》知识蒸馏论文解读
- What is the process of building a small program?
- 针对大量数据,MATLAB生成EXCEL文件并进行排版处理的源码
- Notes on the thinking of software analysis and library acquisition of a Taobao customer
猜你喜欢

三、OpenVINO实战:图像分类

51 single chip microcomputer independent key linkage nixie tube LED buzzer

Notes on the thinking of software analysis and library acquisition of a Taobao customer

4、 Model optimizer and inference engine

The difference and connection between cookies, sessions and tokens

TCL和ELTCL?CDNEXT和CMRL?

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

在win7 上安装 Visual Studio 2019 步骤 及 vs2019离线安装包

Neural network learning

确保PoE设备成功部署的最佳实践
随机推荐
ESXi on ARM v1.2 (2020年11月更新)
Summary of command injection bypass methods
物联网互操作系统:分类、标准与未来发展方向综述
初学者进行传感器选型
Interpreting the knowledge in a neural network
将GrilView中的数据转换成DataTable
EXFO 730c optical time domain reflectometer only has IOLm optical eye to upgrade OTDR (open OTDR permission)
(PHP graduation project) obtained based on PHP novel website management system
(PHP graduation project) based on PHP student daily behavior management system access
使用PowerCli来创建自定义ESXi ISO镜像
详解爬电距离和电气间隙
Geek challenge 2019-sql injection five questions PW
TCL and eltcl? Cdnext and CMRL?
EMC实验实战案例-ESD静电实验
Nsctf web Title writeup
51单片机独立按键联动数码管LED蜂鸣器
8类网线测试仪AEM testpro CV100 和FLUKE DSX-8000哪些事?
基于选择性知识提取的野外低分辨率人脸识别的论文阅读笔记
三、OpenVINO实战:图像分类
Deep learning (I): enter the theoretical part of machine learning and deep learning