excel中如何et vb根据数据自动生成表格_别再纠结了,EXCEL才是真正的神器

f6bbf7ec6557000dfda2115d6b88f09d.png

Courtesy of ArchSmarter

EXCEL是BIM终极搭档的3个理由

3 Reasons Why Excel is the Ultimate BIM Sidekick

本文最初由ArchSmarter发表。你是否玩过“电话”游戏?你需要向旁边的人传达一件事,他们再把这件事传达给其他人。不可避免的是,你的原始信息会在传递过程中逐渐失去原有的意思,最后一个人所提取的信息与你的最初版本往往相差甚远。

现在想象一下,这就是你的项目传递过程,当我们不得不把模型和文件从一种格式转换到另一种格式时,常常会发生这种情况。

所有的传递过程都意味着信息可能丢失。幸运的是,有一种方法可以避免这种数据损失。它来自一个不可思议的来源。

Excel。

是的。这个由微软生产的传统电子表格处理软件是一个超级英雄。

This article was originally published by ArchSmarter.Have you ever played the party game “telephone”? You know the one, where you tell something to the person next to you and they pass it on to the person next to them and so on down the line. Inevitably, your original message is badly mangled and misappropriated by the time it gets back to you. Everyone gets a good laugh at how far the end message is from your original one.

Now imagine that’s your project getting mangled and misappropriated. Not so funny now. But that’s often what happens when we have to translate models and files from one format to another.

All that translation means important information is likely to get lost. Fortunately, there’s a way to avoid this loss of data. And it comes from an unlikely source.

Excel.

Yep, you heard me right. That boring old spreadsheet software is really a superhero in disguise.

善于保存信息的Excel|Excel to the Rescue

f9ea39563ba3458689d2e3b2e3410575.png

Courtesy of ArchSmarter

我最近做了一个项目,主要依靠Excel将几何数据从一种格式转换到另一种格式。Excel是完成这项工作的完美工具。

近期,我咨询了一个专业的立面工程师。他是一个由制造商所雇佣的工程师,并且为停车场设计了一个复杂的金属板立面。

外观设计采用犀牛的Grasshopper插件。它由900个折叠的金属板构成,折叠的模式不同,在金属外观上的穿孔图案也不同。有一些重复的面板类型,但并不多。

犀牛模型导入Revit来生成项目信息。Revit模型包含有多项信息,但却缺乏准确度。因此,幕墙工程师在CATIA中修改各项信息,这样的模型会更加精确。

然而,工程师们所面临的挑战是将CATIA中的模型数据转换成表格和图纸,制造商需要根据这些表格与图纸构建实际的面板。

Excel很容易提取到几何数据,但它需要一些格式转变的过程。同时,模型的大量尺寸属于线性输出。这虽然很好,但制作者需要了解各个面板之间的异同。他们会把这些信息插入软件中来重新创建面板。

通过Excel,我将一系列CATIA数据格式化成一系列的宏文件,并整合成了一个表格,上面有每个面板的细部尺寸,该表格也包含了角度计算公式。

到目前为止的运行情况都还不错。

然后,我编写了另一个宏文件,它使用维度数据来创建各种类型面板的汇总表。我们现在可以确定有多少种面板类型以及哪种类型的面板最多。

这件事开始逐渐变得有趣。

使用这些数据,我打开AutoCAD,并编写了一个宏文件,将这些基本信息与汇总表格生成为图形文件。

在每个图像中,宏文件将这些维度数据插入到每个表格信息之中。

总共花了不到10分钟的时间就生成了300个图纸文件。

很酷吧?

为什么这件事做得这么好?这里有3个原因,来说明Excel是BIM的终极搭档。

1、Excel是通用文件

几乎所有BIM和CAD应用程序都可以以文本或CSV格式导出数据。许多甚至可以直接导出到Excel。这种通用性意味着Excel很容易从软件中获取某种数据。它可能不是你需要的格式,比如CATIA数据,但通常你可以按照需求改变它的格式。

即使没有直接导出到Excel的方法,也可能有一种使用宏文件或软件API来获取数据的方法。正如我后文所描述的那样,Revit不直接链接到Excel,但有许多其他方式来导出数据。

2、Excel对数据情有独钟

Excel与BIM如此合拍的一个主要原因是很多人认为它非常单一化,因为它主要包含有数字信息。事实证明,当你想使用BIM数据时,那Excel正是你所需要的软件。

大多数时候,我们需要组织这些数据元素。考虑到各种构件,数据最好的组织方式是将其整理为表格。Excel有许多用于整理数据的高级工具,包括一些用于总结这些数据的高级工具。

此外,编写复杂公式的能力极大地扩展了Excel的实用性。当然,您也可以使用Revit来创建公式,但远不及Excel强大。如果你需要做一些繁重的计算,可以将文件导出到Excel,计算之后,再把结果送回Revit。

3、Excel很容易实现自动化

在第一个项目中,我编写了一个Excel宏文件,它们易于创建。Excel宏文件用的是Visual Basic语言来编写。虽然这并没有C语言或VB语言强大,但是VBA更加易于操作。

Excel有一个宏记录器,能够记录你在屏幕上的动作,并将它们转换成VBA代码。如果你不确定在宏文件中该如何进行操作,只需在执行这些操作时记录一个宏文件即可,代码便能够自动生成。

我为项目编写的宏文件在开始时非常简单,但随着时间的推移文件会变得非常复杂。结果证明这是件好事。我能够轻松地修改代码以适应各种变化,因为表格信息的重新创建也很容易。

最好的部分是从Excel数据直接生成AutoCAD图纸文件。当你按下一个命令后就自动生成了300个CAD文件时,你会十分惊叹这项功能的强大。另外,AutoCAD使用的也是VBA语言,所以两组宏文件之间有很多共同点。

I recently worked on a project that relied heavily on Excel to translate geometrical data from one format to another. Excel was the perfect tool for the job.

I was consulting with a facade engineer. He was hired by a fabricator to engineer and develop fabrication drawings for a complex sheet metal facade for a parking garage.

The facade was designed in Rhino using Grasshopper. It consists of 900 folded sheet metal panels. The folding pattern varies across the facade as does the perforation pattern on the metal. There’s some repetition of panel types but not a lot.

The Rhino model was brought into Revit to develop construction documents. The Revit model, while sufficient for CDs, wasn’t precise enough for fabrication. So the facade engineer remodeled it in CATIA. This model definitely was precise.

The challenge was translating the data from the CATIA model into the tables and drawings the fabricators would use to actually construct the panels.

The geometrical data was easily extracted to Excel but it needed some serious reformatting. Also, a lot of the dimensions coming out of model were linear. This was good but the fabricator needed to know the angle between the panel segments. They’d plug this information into their bending machine to create the panels.

Using Excel, I wrote a series of macros that reformatted the CATIA data into a new table that listed the dimensions of each panel. This table included formulas that calculated the angles for each panel.

So far so good.

I then wrote another macro that used the dimensional data to create a summary table of panel types. We could now determine how many panel types there were and which types had the most panels.

This is when things got interesting.

Using this data, I hopped over to AutoCAD and wrote a macro that read the Excel summary table and generated drawings for each panel based on a template.

The macro inserted the dimensional data into a table in each drawing.

All told it took the macro less than 10 minutes to generate all 300 of the panel drawings.

Pretty cool!

Why did this work out so well? Here are 3 reasons why Excel is the ultimate BIM sidekick.

1. Excel is universal

Nearly all BIM and CAD applications can export data in text or CSV format. Many can even export directly to Excel. This universality means it’s easy to get some kind of data out of the software. It might not be in the format you need, as in the case with the CATIA data, but you can usually reformat it as needed.

Even if there’s no direct way to export to Excel, there may be a way to get the data out using macros or the software’s API. For example, Revit doesn’t link directly to Excel out-of-the-box but there are a number of other ways to export data, as I outlined in the post.

2. Excel loves data

One of the major reasons why Excel works so well with BIM is the reason many people think it’s so boring – all those rows and columns of numbers. Turns out, when you want to work with BIM data, that’s exactly what you need.

Most of the time, we need to organize categories of elements. Think structural columns or doors or rooms. This data is best represented in tabular format. Excel includes some advanced tools for summarizing this data, such as pivot tables.

Also, the ability to write complex formulas extends Excel’s usefulness considerably. Sure, you can create formulas in Revit but they’re nowhere near as powerful as those in Excel. If you need to do some heavy calculations, it’s much easier to export to Excel, do the calculations there, then bring the results back into Revit.

3. Excel is super easy to automate

One of the first programs I ever wrote was an Excel macro. They’re really easy to write. Excel macros are written using Visual Basic for Applications or VBA. Though it’s not as powerful as C# or VB.Net, VBA is user-friendly and easy to learn.

What’s better is that Excel has a macro recorder that records your actions on the screen and translates them to VBA code. If you’re not sure how to do something in a macro, simply record a macro while doing those actions. The code will get generated automatically.

The macros I wrote for the project started simple but got more complex over time. This turned out to be a good thing. I was able to easily modify the code to accommodate changes and recreating the tables was real easy.

The best part was generating the AutoCAD drawings off the Excel data. There’s something very satisfying seeing 300 CAD files created automatically with the press of a button. Also, AutoCAD uses VBA so there was good common ground between the two sets of macros.

永远的好朋友|Best Friends Forever

鉴于BIM数据的密集性质,这是不可能的,Excel将BIM的终极搭档取代。尽管如此,我确实希望软件公司认识到直接使用数据的重要性,并用Excel创建更好的双向连接。就像星球大战,当Han需要战斗时,始终有Chewie在他的身边。

Given the data-intensive nature of BIM, it’s unlikely that Excel will be replaced as BIM’s ultimate sidekick. With that said, I do hope that software companies recognize the importance of working with data directly and create better two-way connections with Excel. Just like in Star Wars, Han puts up a better fight when he has Chewie at his side.

由专筑网李韧,杨帆编译

【专筑网版权与免责声明】:本网站注明“来源:专筑网”的所有内容版权属专筑网所有,如需转载,请注明出处

private void Save2Excel() { //string file = "F:\\11\\ck.xlsx"; //string path = "F:\\11\\excel\\"; string time = DateTime.Now.ToString("yyyyMMdd"); string file = System.Windows.Forms.Application.StartupPath + "\\ck.xlsx"; string path = System.Windows.Forms.Application.StartupPath + "\\excel\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string saveName1 = path + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; excel = new CCExcel(file,saveName1); excel.Exceldata(); } private void textBox1_TextChanged(object sender, EventArgs e) { Form1.name = textBox1.Text.ToString(); } private void Form1_Load(object sender, EventArgs e) { comboBox1.Text = 11.ToString(); comboBox2.Text = 100.ToString(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Form1.comB1 = comboBox1.Text.ToString(); } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { Form1.comB2 = comboBox2.Text.ToString(); } } public class CCExcel { public Excel.Application appExcel; public Excel.Workbooks wbs; public Excel.Workbook wb; public Excel.Worksheets wss; public Excel.Worksheet ws; private string fileName; private string saveName; public CCExcel(string fileName,string saveName) { // //TODO: 在此处添加构造函数逻辑 // this.fileName = fileName; this.saveName = saveName; } public void Exceldata() { Create(); //Open(fileName); Data2Excel(); Save(saveName); //Save(wb,saveName); //appExcel.ActiveWorkbook.SaveCopyAs(fileName); //判断当前激活的表,并保存这个表。否则,保存时会弹出“是否保存Sheet1.xlsx”的对话框 wb.Close(Type.Missing, Type.Missing, Type.Missing); wbs.Close(); appExcel.Quit(); wb = null; wbs = null; appExcel = null; GC.Collect(); } private void Create()//创建一个Excel对象 { appExcel = new Excel.Application(); wbs = appExcel.Workbooks; wb = wbs.Add(true); //ws = (Excel.Worksheet)wb.ActiveSheet;//这是一个只读sheets集合 //Excel.Worksheet worksheet = wb.ActiveSheet as Excel.Worksheet;//这也是一个只读sheets集合 //Excel.Worksheet ws = (Worksheet)wb.Worksheets[1];//创建工作页sheet单页 ws = wb.Worksheets[1] as Worksheet; //第一个sheet页 ws.Name = "ck"; //这里修改sheet名称 } public void Open(string fileName) { appExcel = new Excel.Application(); wbs = appExcel.Workbooks; wb = wbs.Add(fileName); wb = wbs.Open(fileName,Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值