另外一篇操作excel的参考

Perl处理Excel数据
本文介绍了一个使用Perl脚本从源Excel文件中读取音乐资源名称,并进行特定处理后写入到另一个目标Excel文件的方法。该脚本利用了Win32::OLE模块来操作Excel应用程序,实现了批量处理和数据转换。

1, 和上次那边基本差不多,只不过是个实用的工具,多了些文件操作,模式匹配等,备份供参考

2, 如何打开VBA帮助,office2007里面

新建或打开已有OFFICE文档

ALT+F11
此時出現VBA編程介面,
幫助菜單

打开EXCEL,工具栏中选宏,单击visual basic编辑器,出现了Microsoft visual basic,在其工具栏帮助中找Microsoft visual basic帮助.

#Auther: lancer
#Data: 2009.11.02
#Function: Get name of all muscic from GDD file and process it, then write to another excel file, to be used by code
#Version: 1.00

#Modified
#Version: 1.01 12/17/2009 -- Remove existed files and create a new excel file;

#!usr/bin/perl
use strict;
use warnings;
use Win32::OLE; #import win32 OLE package

my $dir = 'C://iphonegame//ParadiseQuest//iphone//trunk//doc//Production//'; #create two EXCEL files under this dir
my $src_name = $dir."Paradise Quest IPhone GDD"."/.xlsx"; #file to be read and processed
my $dst_name = $dir."test"."/.xlsx"; #file to be written
my $src_sheet_name = 'Sound and iTunes Access'; #sheet number in the source xls
my $dst_sheet_name = 'sheet1'; #sheet number in the destination xls
my $nowstr;
my $sound_name;
my $bgm_count = 0;
my $se_count = 0;
my $align_space = ' ';

print "By lancer/n";
#new a EXCEL application object, then we can operate to excel file
my $app_xls = Win32::OLE->new('Excel.Application', sub{$_[0]->Quit})
or die"Can't install Excel01!";

#open a EXCEL file, 'True' means read only
my $src_book = $app_xls->WorkBooks->Open($src_name, 0, 'True');
my $src_sheet = $src_book->Worksheets($src_sheet_name); #selete a worksheet

unlink $dst_name;
#while(<STDIN>){
#
#}
print("delete primal file/n");

#open(OUTFILE, ">$dst_name")||die "Open file [$dst_name] error!";
#close(OUTFILE); #close excel file handle
##while(<STDIN>){
##
##}
#print("open file/n");
#
#while(<STDIN>){
#
#}
my $dst_book = $app_xls->WorkBooks->Add();

print("create new file/n");
#$dst_book->SaveAs($dst_name);
my $dst_sheet = $dst_book->Worksheets(1);
$app_xls->{DisplayAlerts} = 'False'; #close the alert of excel, such as change or save

for (my $i = 1; $i < 200; $i++) {
$nowstr = $src_sheet->Cells($i,'D')->{Value}; #get data from a cell
if($nowstr){
if($nowstr eq 'bgm'){
$sound_name = $src_sheet->Cells($i,'C')->{Value}; #get data from a cell
process_bgm_name($sound_name);
}elsif($nowstr eq 'se'){
$sound_name = $src_sheet->Cells($i,'C')->{Value}; #get data from a cell
process_se_name($sound_name);
}
}
}

#$dst_book->Save; #save the change to destination xls
$dst_book->SaveAs($dst_name);
print("Finish process, file saved. Press Enter to quit!/n");
$app_xls->{DisplayAlerts} = 'True'; #restore the alert of excel

undef $src_book;
undef $dst_book;
undef $app_xls; #close the opend excel application

my $a;
$a = <>;


sub process_bgm_name{
++$bgm_count;
my $bgm_str = $_[0];

#process enum value
my $enum_str = uc($bgm_str);
$enum_str =~ s//)?.(WAV|M4A)//;
$enum_str =~ s// /(|[() -]/_/g;
if($bgm_count==1){ #first enum
$enum_str .= ' = 0';
}
$enum_str = $align_space . 'MUSIC_BGM_' . $enum_str . ',';


#process char array value
my $char_str = $bgm_str;
$char_str =~ s/.wav/.m4a/;
$char_str = $align_space . '"' . $char_str . '",';

print "$enum_str/n";
print "$char_str/n";
$dst_sheet->Cells($bgm_count,'A')->{Value} = $enum_str; #write a data to a cell
$dst_sheet->Cells($bgm_count,'B')->{Value} = $char_str;
}

sub process_se_name{
++$se_count;
my $se_str = $_[0];

#process enum value
my $enum_str = uc($se_str);
$enum_str =~ s//)?.WAV//;
$enum_str =~ s// /(|[() -]/_/g;
if($se_count==1){ #first enum
$enum_str .= ' = 0';
}
$enum_str =$align_space . 'SOUND_SE_' . $enum_str . ',';

#process char array value
my $char_str = $se_str;
$char_str = $align_space . '"' . $char_str . '",';
print "$enum_str/n";
print "$char_str/n";
$dst_sheet->Cells($se_count,'C')->{Value} = $enum_str; #write a data to a cell
$dst_sheet->Cells($se_count,'D')->{Value} = $char_str;
}

内容概要:本文介绍了一个基于Matlab的综合能源系统优化调度仿真资源,重点实现了含光热电站、有机朗肯循环(ORC)和电含光热电站、有机有机朗肯循环、P2G的综合能源优化调度(Matlab代码实现)转气(P2G)技术的冷、热、电多能互补系统的优化调度模型。该模型充分考虑多种能源形式的协同转换与利用,通过Matlab代码构建系统架构、设定约束条件并求解优化目标,旨在提升综合能源系统的运行效率与经济性,同时兼顾灵活性供需不确定性下的储能优化配置问题。文中还提到了相关仿真技术支持,如YALMIP工具包的应用,适用于复杂能源系统的建模与求解。; 适合人群:具备一定Matlab编程基础和能源系统背景知识的科研人员、研究生及工程技术人员,尤其适合从事综合能源系统、可再生能源利用、电力系统优化等方向的研究者。; 使用场景及目标:①研究含光热、ORC和P2G的多能系统协调调度机制;②开展考虑不确定性的储能优化配置与经济调度仿真;③学习Matlab在能源系统优化中的建模与求解方法,复现高水平论文(如EI期刊)中的算法案例。; 阅读建议:建议读者结合文档提供的网盘资源,下载完整代码和案例文件,按照目录顺序逐步学习,重点关注模型构建逻辑、约束设置与求解器调用方式,并通过修改参数进行仿真实验,加深对综合能源系统优化调度的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值