Archive for 01月 2008

Google Chart API指南(3)

前面部分参见Google Chart API指南(2)
图表尺寸
使用chs=<width in pixels>x<height in pixels>指定图表尺寸,例如,chs=300×200生成300像素宽和200像素高的图表。
图表的最大可能区域是300000像素。最大极限的高度或宽度是1000像素,最大尺寸的例子是1000×300、300×1000、600×500、500×600、800×375和375×800。
图表数据
下面的编码格式是有用的:

  • 简单的编码有62种不同值的精度。允许每个数据点五个像素,对于折线图和条形图达到大约300像素是足够的。简单的编码适合于所有其他类型的图表而不管其大小。
  • 文本编码有1000种不同值的精度,使用在0.0和100.0之间的浮点数字。允许每个数据点五个像素,整数(1.0、2.0,等等)对于折线图和条形图达到大约500像素是足够的。如果需要更高的精度,包括单个的小数位(例如35.7)。文本编码适合于所有其他类型的图表而不管其大小。
  • 扩展的编码有4096种不同值的精度,最好用于需要大数据范围的大图表。

注意:文本编码需要几个字符来编码单个的数据点。简单的编码是最有效的,只为每个数据点使用一个字符。
简单的编码
使用chd=s:<chart data string>指定简单的编码,其中<chart data string>包含字符:A到Z、a到z、0到9、下划线(_)和逗号(,)。
注意:

  • 大写字母A = 0、B = 1 …… Z = 25 。
  • 小写字母a = 26、b= 27 …… z = 51。
  • 零 (0) = 52 …… 9 = 61。
  • 使用下划线(_)指定忽略的值。
  • 如果有多组数据,使用逗号(,)分隔每一组。

例如,两组数据:chd=s:ATb19,Mn5tz,其中在每一个数据组中 — A代表0,T 代表19,b 代表27,1 代表53,9 代表 61。
注意:对于简单的编码,Chart API在图表的底部使用值0绘制点,在顶部为61,沿着y轴均匀展开所有其他值。
文本编码
使用chd=t:<chart data string>指定文本编码,其中<chart data string>由从0(0.0)到100.0的浮点数、-1和管道字符(I)组成。
注意:

  • Zero (0.0) = 0, 1.0 = 1 and so on up to 100.0 = 100.
  • 零(0.0)=0,1.0=1…….直到100.0=100。
  • 使用-1指定忽略的值。
  • 如果有多组数据,使用管道字符(I)分隔每组数据。

例如:chd=t:10.0,58.0,95.0|30.0,8.0,63.0
注意:对于文本编码,Chart API在图表底部使用值0绘制点,在顶部为100.0,沿着y轴均匀展开所有其他值。
扩展的编码
使用chd=e:<chart data string>指定扩展的编码,其中<chart data string>包含成对字符:A 到 Z, a 到 z, 0 到 9, 连字号 (-), 句点 (.), 下划线 (_), 和逗号 (,).
注意:

  • AA = 0, AZ = 25, Aa = 26, Az = 51, A0 = 52, A9 = 61, A- = 62, A. = 63
    BA = 64, BZ = 89, Ba = 90, Bz = 115, B0 = 116, B9 = 125, B- = 126, B. = 127
    .A = 4032, .Z = 4057, .a = 4058, .z = 4083, .0 = 4084, .9 = 4093, .- = 4094, .. = 4095.
  • 使用两个下划线(__) 指定忽略的字符。
  • 如果有多组数据,使用逗号(,)分隔每组数据。

注意:对于文本编码,Chart API在图表底部使用值0绘制点,在顶部为4095,沿着y轴均匀展开所有其他值。
编码数据的JavaScript代码片断
编程转换现实数据成Chart API数据比手工转换更容易。
下面的JavaScript代码片断编码数据组成简单的编码。必须提供正数的数组作为数据组,不是正数的数据组值被编码为使用下划字符(_)的忽略值。
调用simpleEncode函数传递数组(values)和数组中的最大值(maxValue)。对于折线图和条形图,如果希望在最大值和图表顶部之间有空间,则使maxValue比数组中的最大值更大。
var simpleEncoding = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789′;

function simpleEncode(values,maxValue) {

var chartData = ['s:'];
  for (var i = 0; i < values.length; i++) {
  var currentValue = values[i];
  if (!isNaN(currentValue) && currentValue >= 0) {
  chartData.push(simpleEncoding.charAt(Math.round((simpleEncoding.length-1) * currentValue / maxValue)));
  }
  else {
  chartData.push(’_');
  }
  }
return chartData.join(”);
}
间隔尺寸的引导线
当心不要高估图表所需要的数据点数字。例如,要显示过去10年期间Britney Spears是如何流行,汇总每天搜集的查询导致多于3600个值。这将在URL中传递太多的数据,同时以这个间隔尺寸绘制图形没有意义:在1024像素宽的屏幕中一个数据点在屏幕中大约是一个像素的四分之一。正如下面的例子所演示的。
200×100的图表,具有20个数据点(每个数据点10像素):
GooglechartAPISample22
40个数据点(每个数据点5像素):
GooglechartAPISample23
80个数据点(每个数据点仅2.5像素):
GooglechartAPISample24
待续……

标签: , ,

微软OOXML再闯国际标准关 2000页修改后文档公布

据cnBeta的消息:
国际标准组织ISO计划于今年2月底再次开会讨论微软文档标准OOXML,如果不出意外,OOXML标准可能在此次会议期间顺利通过投票关,成为继ODF之后的第二个文档国际标准.
1月24日晚些时候,微软中国董事长、微软研发集团主席张亚勤向腾讯科技证实了这一消息.会议将于2月底开始,在就微软技术改进的效果展开讨论后,将于3月底前进行投票,以决定是否采纳OOXML标准成为国际标准.去年9月,这一标准在包括中国业界在内的反对声中受挫.
微软公布两千页修改意见
按照安排,2月底ISO将召开BRM(问题解决)会议,就微软所提出的文档修改意见进行讨论.届时,ISO将由此前的第一联合技术委员会(JTC1),转移至SC35专门委员会来讨论这一事件.
此前,在2007年9月国际标准组织ISO的投票中,中国政府以“没有足够时间评估微软标准文件”为由投下反对票.有专家介绍,同期全球各个国家一共提出了OOXML标准中存在的3522项问题,最终微软去除重复项后总结成1000多项.
数月之后的1月19日,微软正式公布了上述1000多项、近2千页的修改文档.目前,中国有关部门及相关软件企业,正在就文档展开新一轮评估.
中国工程院院士倪光南曾指出,微软标准至少存在四大缺陷,分别为“OOXML只支持Windows一个平台,并不支持Linux;包含大量微软私有标准和技术,排除现有国际技术标准和技术;只有微软Office 2007单个产品能实现其全部功能,其他产品最多只能兼容部分;对中文和其他语言支持不够,不适合中国应用的需求;”
最新的修改文档,都在围绕上述核心问题展开.当天晚间,张亚勤表示,微软在Office技术方面的开放已经更进一步.胡才勇也向腾讯科技证实,他们正在就修改文档进行全面评估,尚无法做出最终结论.不过,从目前已有的情况看,“微软确实比以前更开放了些”.
向中国企业频频示好
而在新一轮投票开始前,微软中国也频频向此前的反对者及中国政府示好.
张亚勤表示,目前微软正在就标准问题与中国软件企业进行沟通.这些沟通包括了也此前反对声最坚决的中国办公软件厂商及相关专家.胡才勇证实,微软确实与各家企业进行了接触.
在此之前,对沟通策略的不重视迫使微软中国面临如潮般的反对声.一度市场传闻,微软大中华区CEO陈永正离职正源于此.当然,这一说法遭到了微软的否认.
1月24日下午,张亚勤公开表示,微软将全力支持中国文档标准UOF,并希望与之一起进入国际文档标准行列.斯时是IT时代周刊举办的年会,曾公开质疑OOXML标准的倪光南院士也正在现场聆听.
张亚勤事后坦承,此前的演讲并未计划涉及OOXML,但在“开放”的大主题下他认为有必要提及.他在演讲中说,“微软中国是中国的软件企业,如果中国信息产业不成功,微软中国就一定也不能成功”.
对于“愿与中国文档标准UOF一起进入国际文档标准行列”的表态,张亚勤也解释,其中包括微软在UOF成为国际标准的努力中投下支持票.
去年9月冲刺国际标准暂时受挫后,微软中国也随即委托北航开发了文档格式转换器,放在网上提供免费下载.利用这一转换器,用户可以在三大文档格式之间自由转换.张亚勤称,这一转换器可以实现无缝转换,文件“几乎不会失真”.
三大文档标准格式分别为2007年5月成为国际标准的OpenDocumen文档格式(简称为ODF)、中国国家标准《中文办公软件文档规范》(简称为UOF)、及微软Office Open XML(简称为OOXML).
修改文档评估尚需时间
对于张亚勤伸出的和解橄榄枝,倪光南院士没有立即表态.当天晚些时候,他对腾讯科技表示,微软OOXML标准有改进,但评估文件依然庞大,尚没有完成全面评估.
红旗两千胡才勇也表示,他们正在就修改文档进行全面评估,尚需要时间.
而面对即将到来的新一轮会议及投票,有业内企业表示,时间确实非常紧张.但如果不出意外的话,微软OOXML可能最终完成自己的国际标准计划.

标签: 没有标签

编写VBA代码的10大戒律

http://excelusergroup.org/forums/p/116/276.aspx中的找到的。
对于VBA代码编写者,如果必须说出好的VBA程序的10大戒律,我很想知道会选择什么?下面是我的(没有按照特定的顺序):

  • 应该声明所有的变量。Option Explicit在编写良好的代码中不是一个可选项。
  • 应该为变量、过程和函数提供有意义的名称。不是所有方面都需要长的名称,但是仅知道短的缩写将会使代码对他人来说难以阅读。
  • 应该有代码的文档说明。越多越好。
  • 应该在使用完成后恢复设置。如果混淆了已更改的设置,应该将它们恢复。对于这些,代码应该只执行必须要进行的操作。不多不少最好。
  • 应该尽可能的保持范围为私有的。如果能够设置为私有的,那么就应该这样设置。这条规则适用于过程、函数和变量。
  • 为了省事而不使用错误处理的代码不会认为是好的代码。避免错误最好的方式,是一旦发现错误就能立即处理它们。
  • 应该提供代码的来源。如果从网络中或新闻组中复制了一些具有创新性的或精心制作的代码,应注明其来源。
  • 不应该弄乱其他人的工作。如果更改某人的代码,应该注明哪部分是自已的。
  • 应该使代码美观。外观醒目、缩进代码、在适当的位置添加断行、在代码断添加空行和注释行。
  • 保持简洁。一个过程应该只执行一项操作,一个函数应该只返回一个值。越简短通常越好。在模块中使用常见的简单的主过程组织其他过程,主过程调作简单的子过程。将相似的代码组合在一起放置到模块中。
  • 除了作为错误处理的一部分外,决不要使用Goto。如果需要使用Goto,则停下来,考虑一下,总会有更好的方法。
  • 当代码崩溃时不要责怪最终用户。如果代码已编写良好,那么会让最终用户选择,而不会发生一些愚蠢的事情。
  • 不应该违反不理解的规则。规则能避免陷入麻烦。在不遵守规则之前,确保已理解它们并已经过考虑。

是的,已超过了10条,但我必须写出来。我很好奇您有没有其他的想法,如果有,您也可以在下面写下来。
英文原文:
I am curious to know from other VBA coders if you had to write the 10 commandments of good VBA programming what would you choose? Here are mine (in no particular order)…

(1)Thou shalt declare all variables. NO EXCUSES! Option Explicit is not an option in well written code.
(2)Thou shalt give variables, procedures and functions meaningful names. Not everything requires a long drawn out name but short acronyms known only to you just make your code unreadable to others.
(3)Thou shalt document code. More is better.
(4)Thou shalt put things back the way you found them. If you mess with settings put them back the way you found them. (5)Code should do exactly what it has to do. Nothing more. Nothing Less.
(6)Thou shalt keep scope as private as possible. If it can be declared private then it should be declared that way. That applies to procedures, functions and variables.
(7)Thou shall not use the error handler as a convenience to account for poorly written code. Avoiding errors is almost always preferable to dealing with them once they occure.
(8)Thou shalt give credit where credit is due.If you copy some innovative or ellaborate code from the web or a news group document where it came from.
(9)Thou shalt not muck with someone elses work. If you change someone elses code document what part is yours.
Thou shalt make it pretty. Appearance counts. Indent your code. Add line breaks where appropriate. Add empty lines and comment lines to section your code.
(10)Thou shalt keep it simple. One procedure should do one thing. A function should return a value. Shorter is generally better. Organize our procedures in a modular fashion with simple main procedures calling simple sub procedures. Organize your code into modules that group similar code together.
(11)Thou shalt never use Goto’s except as part of the error handler. If you feel like you need to use a goto… stop and think about it. There is always a better way
(12)Thou shalt not blame the end user when your code bombs. If it was well written it would handle whatever stupid things the end user has chosen to do.
(13)Thou shalt not break rules that you don’t understand. The rules are there to keep you out of trouble. Before you break the rules make sure you understand the consequences and account for them.
I know that that is more than 10 but I did not have to etch mine onto a stone tablet. Just curious what others think and what items they would add to the list.
回贴:
 1、提供健壮的代码解决方案。
Provide robust code solutions (i e avoid flashy solutions).
2、基于其作用域级别声明变量。
Declare variables based on their scope’s level.
3、需要时,应给最终用户提供相关的且便于理解的错误信息。
Provide relevant and understandable error messages (when needed) to the end users.
4、创建用户友好的且流程处理的逻辑UI。
Create user friendly and flow process’s logical UI.
5、对于大型解决方案,使用帮助文件并创建系统文档。
For larger solutions use helpfile(s) and create system documentation.
6、过程和函数应该只有1个出口。不要在代码中随意放置Exit Sub和Exit Function行。
Thou procedures and functions shall have only 1 exit point. Don’t put Exit Sub and Exit Function lines here there and everywhere throughout your code. It gets to be darn near impossible to debug procedures that may or may not exit at various points. I am not saying that Exit does not have it’s place. I use it at the beginning of procedures and functions all the time to see if I want to execute the main body of code. But once I enter the main body of code I avoid Exit lines. And don’t use End Sub. End Sub is almost without exception always a bad idea…
7、Just a couple of points. Comments in code are no substitute for proper documentation of what your program does and how it does it. I know that firing up Word and creating some proper documentation is boring, but it needs to be done.
The other important thing to remember about commentary is that it’s there to expalin why a particular line of code is there. Commentary is not there to explain what’s happening: The clarity of BASIC and your coding style should be able to make it quite clear what each line is doing.
My addition to the commandments would be “Don’t hard-code strings and magic numbers - use constants and enums. This has the double benefit of being more maintainable and making code more readable.”
8、For business projects, I would add another - keep all business logic out of code as far as possible, because it is much harder to maintain and check than if it was in a spreadsheet.
Having seen the generally low level of user skills, which makes it important to stay as simple as possible, I do as much as possible in worksheets, using code for automation and utility functions - but not for business calculations.
9、From my days writing C I got used to everything being a function. Which is all well and good for C but IMO in VBA Subs do sutff and Functions return values. I try to keep the two separated along those lines. That way I have some idea what is expected to happen even before I look at the code. One pet peave of mine is that functions return values and if you don’t specify the type then the function returns a variant. Perhaps that should be another commandment.
#15 - Thou shalt specify the return types on functions. Even if you intend the function to return a variant, specify it.
Which leads me to my next commandment
#16 - Thou shalt specify the manner in which arguments are passed. The default is that arguments are passed by reference. That being said arguments should be passed by value except where you need to permanently alter the variable(IMO). In either case specify how the argument is being passed so that it is obvious what is intended and to demonstrate that you took the time to evaluate the appropriate way to pass the variable.
10、That would be another of my commandments: Be absolutely explicit - always declare both bounds of your array dimensions.
下面是在http://www.utteraccess.com/forums/printthread.php?Board=24&main=1317632&type=post中发现的:
1) Avoid ELSE GOTO and ELSE RETURN.
2) Each module should do one thing well.
3) Use debugging compilers. (Option Explicit)
4) Avoid multiple exits from loops.
5) 10.0 times 0.1 is hardly ever 1.0.
6) Don’t compare floating point numbers just for equality.
7) Make it right before you make it faster.
8) Keep it right when you make it faster.
9) Make it clear before you make it faster.
10) Don’t sacrifice clarity for small gains in “efficiency.”
11) Don’t strain to re-use code; reorganize instead.
12) Keep it simple to make it faster.
13) Don’t diddle code to make it faster – find a better algorithm.
And perhaps most importantly…
14) Don’t patch bad code – rewrite it.
不好意思,时间仓促,一部分未译成中文,偷懒了… :)

标签: 没有标签

Excel美人鱼动画

J-Walk Blog中发现的,很是有趣。
xlmermaidmain
He shaded the cells on 16 worksheets, did a screen capture of each, and made an extremely lifelike animated GIF.(渐变16个工作表中的单元格,捕捉每个屏,使得其极像一个GIF动画)
谁说Excel没有价值?

标签: 

Australian Excel User Conference

Excel User Conference网站消息,2008年澳大利亚Excel用户大会将在悉尼举行,时间是3月12日至3月14日共3天。
主要的演讲者都是大名鼎鼎的Excel重量级人物,他们是Kusleika (Daily Dose of Excel)、Damon Longworth、John Walkenbach(J-Walkblog.com)和Charles Williams(Decision Models).
大会分两天分别面向中级和高级用户。请关注:
http://www.exceluserconference.com/AUEUC.html

标签: