【免费】GAMS与EXCEL互动的方法【免费】
发布:tylerma3223 | 分类:会计库
关于本站
人大经济论坛-经管之家:分享大学、考研、论文、会计、留学、数据、经济学、金融学、管理学、统计学、博弈论、统计年鉴、行业分析包括等相关资源。
经管之家是国内活跃的在线教育咨询平台!
经管之家新媒体交易平台
提供"微信号、微博、抖音、快手、头条、小红书、百家号、企鹅号、UC号、一点资讯"等虚拟账号交易,真正实现买卖双方的共赢。【请点击这里访问】
论文
- 毕业论文 | 写毕业论文
- 毕业论文 | 为毕业论文找思路
- 毕业论文 | 可以有时间好好写 ...
- 毕业论文 | 毕业论文如何选较 ...
- 毕业论文 | 毕业论文选题通过 ...
- 毕业论文 | 还有三人的毕业论 ...
- 毕业论文 | 毕业论文答辩过程 ...
- 毕业论文 | 本科毕业论文,wi ...
考研考博
- 考博 | 南大考博经济类资 ...
- 考博 | 考博英语10000词汇 ...
- 考博 | 如果复旦、南大这 ...
- 考博 | 有谁知道春招秋季 ...
- 考博 | 工作与考博?到底 ...
- 考博 | 考博应该如何选择 ...
- 考博 | 考博失败了
- 考博 | 考博考研英语作文 ...
留学
- 日本留学 | 在日本留学心得
- 日本留学 | 日本留学生活必需 ...
- 日本留学 | 【留学日本】2015 ...
- 日本留学 | 日本海外留学8年来 ...
- 日本留学 | 日本留学费用_日本 ...
- 日本留学 | 求在日本留学的师 ...
- 日本留学 | 日本留学的有没有 ...
- 日本留学 | 日本留学
TOP热门关键词
坛友互助群 |
扫码加入各岗位、行业、专业交流群 |
无论读取还是保存,都需要使用gdx文件作为中介。
读取时,先将excel的数据转换到gdx中,然后读取数据至内存。
eg:
set
i/usa,eu,row/
t/2005*2010/
;
parameters
LandRate(i,t)
CapitalRate(i,t)
SkLabRate(i,t)
UnskLabRate(i,t)
NatResRate(i,t)
test(i)
;
$call "gdxxrw ../data/trend.xlsx output=../data/trend.gdx par=NatResRate rng=NatRes! par=LandRate rng=Land! par=CapitalRate rng=Capital!par=SkLabRate rng=SkLab! par=UnskLabRate rng=UnskLab!"
$GDXIN ../data/trend.gdx
$load LandRate CapitalRate SkLabRate UnskLabRate NatResRate
$GDXIN
display
LandRate
CapitalRate
SkLabRate
UnskLabRate
NatResRate;
将数据保存至excel时,首先要将内存中的变量或者参数保存成gdx形式,如后转到到excel。
eg:
execute_unload "../data/ReTest.gdx" NatResRate
execute 'gdxxrw.exe ../data/ReTest.gdx output=../data/ReTest.xlsx par=NatResRate rng=sheet1!'
注意:当data目录下已经存在ReTest.xlsx文件时,再次保存相同的文件名,并不会覆盖原来的文件,而是在这个文件上继续添加数据。
IntroductionThis section gives a brief overview on how to use the GDX facilities in GAMS to read data from Excel and to write data to Excel. For more detailed information see the Appendix "GDX Facilities and Tools" of the GAMS User's Guide.Sample model to write an Excel file: gms2xls.gmsSample model to read from an Excel file: xls2gms.gmsSystem Requirements: A GAMS system Distribution 21.0 or later is required.
IntroductionGAMS communicates with Excel via GDX (GAMS Data Exchange) files.A GDX file is a file that stores the values of one or more GAMS symbols such as sets, parameters variables and equations. GDX files can be used to prepare data for a GAMS model, present results of a GAMS model, store results of the same model using different parameters etc. A GDX file does not store a model formulation or executable statements.
GDX files are binary files that are portable between different platforms. They are written using the byte ordering native to the hardware platform they are created on, but can be read on a platform using a different byte ordering.
In order to write data from GAMS to Excel, the user writes a GDX file and then writes the Excel file from the GDX file.
GAMS ----> GDX ----> Excel This is practically seamless for the user and requires few commands. The process to import data from an Excel file to GAMS is similar: Excel ----> GDX ----> GAMS Example: GAMS to ExcelWe will build on the simple transportation model from the GAMS Model library and write the solution x and the marginals of x to an Excel file.After the solve statement, we unload the data (x.L and x.M) to a GDX file using the execute_unload command:
execute_unload "results.gdx" x.L x.M Note that the execute_unload command is executed during the actual execution phase (not during compilation time as $ control options) and creates a GDX file called results.gdx.Now let us write the data from the GDX file to an Excel file called results.xls. We do this using the GDXXRW utility
execute 'gdxxrw.exe results.gdx var=x.L' execute 'gdxxrw.exe results.gdx var=x.M rng=NewSheet!f1:i4' For the first call for x.L, there is no range specified and the data is written in cell A1 and beyond in the first available sheet. For the marginals x.M data will be written to cells F1:I4 in the sheet NewSheet. Note that we specified var=x.L and var=x.M. If the user wishes to write parameters to the Excel file, the relevant command is par. See the GDX facilities in GAMS document for further details.The complete GAMS model: gms2xls.gmsThe resulting GDX file: results.gdxThe resulting Excel file: results.xlsExample: Excel to GAMSAgain, we will use the transportation model and make use of the results.xls file created by the previous model. First we will create the GDX file from the Excel file. We will make use of the GDXXRW utility: $CALL GDXXRW.EXE results.xls par=Level rng=A1:D3 Note that since we are using the $CALL command, this occurs during the compilation phase and not during execution time. We specify that the data in the range A1:D3 is read in as a parameter called Level. The resulting GDX file will be called results.gdxBefore we can read in the data, we must define a parameter called Level over the appropriate sets:
Parameter Level(i,j); $GDXIN results.gdx $LOAD Level $GDXIN The GDXIN results.gdx command specifies that data will be read in from the appropriate GDX file. We then import data structures values using the $LOAD command. When we are finished, we terminate with $GDXIN.In the example below, we then fix the level values of the variable x to the parameter Level so that solving results in a trivial fixed model.The complete GAMS model: xls2gms.gms
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
您可能感兴趣的文章
本站推荐的文章
- 哲学名言 | 【独家发布】经典哲学名言
- 哲学书籍 | 求推荐一本讲人生目标的哲学书籍 ...
- 哲学书籍 | 经济人,开拓你逻辑思维的哲学书 ...
- 哲学书籍 | 哲学书籍
- 哲学书籍 | 哲学书籍
- 哲学书籍 | 哲学书籍
- 哲学书籍 | 经典的哲学书籍
- 哲学书籍 | 发22本经典的经济学及哲学书籍《 ...
人气文章
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。