天生我才必有用

使用PHP读取Excel文件

Posted in PHP    作者:Ray    2009年十一月20日

可能这应该算得上一个很古老的问题,解决的也有多种多样,不过Internet上比较多的是Excel的保存的范例,所以写一篇如何读取Excel,可能对大家有所帮助。

  1. 使用COM接口调用,把Excel应用程序作为一个Server,PHP间接使用Excel来读取文件。
  2. 使用PHPExcel的程序包。它的优点不单单读取资料而且可以保存资料为Excel文件,同时还支持Excel 2007的格式。方法就是把Excel看作一个普通的Excel文件读取。
  3. 还有一种是PHP Excel Reader,它把Excel文件看作一个二进制文件读取,不过不支持新版本Excel文件。

方法2可能看起来不错,不过当你在读取资料大比较大的文件时,会有一个致命的缺点:内存溢出。因为它必须把整个Excel读入内存。有点像XML的DOM接口,不清楚是否有类型XML的SAX的方法。

方法3有类似方法2内存溢出的问题,同时对新版的支持较差。

方法1应该是属于非常传统的方式,只有支持COM程序接口就可。同时只有你能用当前安装的Excel打开此文件,你就可以通过COM接口读取文件。缺点就是你必须在你的电脑上安装Excel。不过对于大文件现在只能使用这个方法。

$doc = "test.xls" ;
$excel_app = new COM("Excel.Application", NULL, CP_UTF8) or die ("Please install the Excel. \n");

#$excel_app->Visible = 1;

$workbook = $excel_app->Workbooks->Open($doc) or die("Can't open ".$doc);
$worksheet = $workbook->WorkSheets(1);
$worksheet->activate;

$min_row    = $worksheet->UsedRange->Row;
$min_col    = $worksheet->UsedRange->Column;
$max_row    = $worksheet->UsedRange->Rows->Count;
$max_col    = $worksheet->UsedRange->Columns->Count;

for ($row = $min_row ; $row < $max_row; $row ++){
    for ($column = $min_col ; $column <= $max_col; $column ++){
       $value = $worksheet->Cells($row, $column)->value;
       echo $value."\n";
    }
}
$excel_app->Workbooks->Close();
$excel_app->Quit();
标签: , , ,

Programming Cocoa with Ruby: Create Compelling Mac Apps Using RubyCocoa

Posted in Ruby    作者:Ray    2009年八月17日

ruby

Introduction:

This is a book for the Ruby programmer who’s never written a Mac app before. Through this hands-on tutorial, you’ll learn all about the Cocoa framework for programming on Mac OS X. Join the author’s journey as this experienced Ruby programmer delves into the Cocoa framework right from the beginning, answering the same questions and solving the same problems that you’ll face.

Together you’ll build a single application that threads throughout the book, and it’s not a toy. You’ll cover topics that may not be the flashiest parts of Cocoa, but they’re ones you’ll need to know to create robust, feature-rich applications for yourself. And you’ll learn more than just Cocoa and RubyCocoa, you’ll get first-hand effective agile development practices. You’ll see test-first development of user-interface code, little domain-specific languages that take advantage of Ruby features, and other Rubyish tricks.

At the end of the book, you’ll be ready to write a real Mac OS X application that can be distributed to real users.

Publisher: Pragmatic Bookshelf

Date: 2009-08-10

ISBN: 1934356190

Page: 300 pages

Size: 6,2 MB

(全文…)

标签: , ,

Developing Facebook Platform Applications with Rails

Posted in Ruby    作者:Ray    2009年八月17日

facebook

Introduction:

Developing Facebook Platform Applications with Rails leads you through the steps necessary to build your first application. You’ll get hands-on experience with Facebook technologies such as FBML and FQL, and master messaging and news feeds.

You’ll do more than just study the Facebook API-you’ll get practical tips from an experienced Facebook developer. We’ll cover advanced techniques such as AJAX and asynchronous messaging, and you’ll see how to slash development time with facebooker, the leading Ruby library for Facebook Platform development.

Together, we’ll build Karate Poke, a real Facebook Platform application, from configuration to deployment. You’ll get deep into Facebook requests right off the bat. From there, you’ll build the core of Karate Poke and then get a detailed look at the Facebook canvas and social features. We’ll finish by looking at advanced features and tips for handling millions of users.

Developing for the Facebook Platform can seem like a different world at first. Developing Facebook Platform Applications with Rails is your tour guide.

Publisher: Pragmatic Bookshelf

Date: 2008-10-28

ISBN: 1934356123

Page: 196 pages

Size: 2,8 MB

(全文…)

标签: , ,

Pragmatic Version Control Using Git

Posted in eBook    作者:Ray    2009年八月14日

Pragmatic Version Control Using Git

Introduction:

# Whether you’re making the switch from a traditional centralized version control system or are a new programmer just getting started, this book prepares you to start using Git in your everyday programming.Pragmatic Version Control Using Git starts with an overview of version control systems, and shows how being distributed enables you to work more efficiently in our increasingly mobile society. It then progresses through the basics necessary to get started using Git.You’ll get a thorough overview of how to take advantage of Git. By the time you finish this book you’ll have a firm grounding in how to use Git, both by yourself and as part of a team. Learn how to use how to use Git to protect all the pieces of your project
# Work collaboratively in a distributed environment
# Learn how to use Git’s cheap branches to streamline your development
# Install and administer a Git server to share your repository

About the Author
:
Travis Swicegood is part of the AppDev team at Ning helping to build the platform that lets you create a social network. He’s been programming professionally for nearly a decade, but would still be doing it for fun even if he was selling cars for a living.

He is actively involved in the development of several open-source automation tools in the PHP community, including several testing frameworks. He is also an active member of his local programming community, founding Lawrence Programmers. When not learning new programming languages or tools, he’s normally found on one of his many bikes, tasting his latest culinary creation, or experimenting with a new home brew.

Publisher: Pragmatic Bookshelf
Publish Date: December 28, 2008
ISBN: 1934356158
pages: 190
Size: 6 MB

(全文…)

标签: , ,

OReilly Version Control with Git

Posted in eBook    作者:Ray    2009年八月14日

oreilly_git

Version Control with Git takes you step-by-step through ways to track, merge, and manage software projects, using this highly flexible, open source version control system. Git permits virtually an infinite variety of methods for development and collaboration. Created by Linus Torvalds to manage development of the Linux kernel, it’s become the principal tool for distributed version control. But Git’s flexibility also means that some users don’t understand how to use it to their best advantage. Version Control with Git offers tutorials on the most effective ways to use it, as well as friendly yet rigorous advice to help you navigate Git’s many functions. With this book, you will: * Learn how to use Git in several real-world development environments * Gain insight into Git’s common-use cases, initial tasks, and basic functions * Understand how to use Git for both centralized and distributed version control * Use Git to manage patches, diffs, merges, and conflicts * Acquire advanced techniques such as rebasing, hooks, and ways to handle submodules (subprojects) * Learn how to use Git with Subversion Git has earned the respect of developers around the world. Find out how you can benefit from this amazing tool with Version Control with Git.

Publisher: OReilly
Publish Date: 06-2009
ISBN-10: 0596520123
Size: 5 MB
Pages: 330 Pages

(全文…)

标签: , ,

Zend Framework 1.9发布

Posted in PHP, 技术    作者:Ray    2009年八月10日

感觉现在Zend Framework 更新了很快,可能和日益受到关注有关。不知不觉中已经发布到了1.9版本。

更新的内容可以查看:http://devzone.zend.com/article/4906-Zend-Framework-1.9.0-Released

我对Zend_Test_PHPUnit_Db和Zend_Queue比较感兴趣,特别是Zend_Queue的支持,特别是加入了对MemcacheQ的原生支持。

有空学习一下这些新内容,感觉Zend Framework在逐渐缩短和RoR之间的差距。在新版本发布之际,更新一下Zend Framework的帮助chm.

标签: ,

Zend Framework command line console tools

Posted in PHP    作者:Ray    2009年七月21日

Zend Framework Command Line Console Tool v1.8.4

Usage:

zf [--global-opts] action-name [--action-opts] provider-name [--provider-opts] [provider parameters ...]

Providers and their actions:

  • Version

zf show version mode[=mini] name-included[=1]
查看当前Zend Framework的版本信息。你可以使用zf show version ? 获得更多的帮助信息。

  • Phpinfo

zf show phpinfo
查看PHP配置信息。

  • Manifest

zf show manifest
查看项目的Manifest

  • Profile

zf show profile
查看项目的Profile

  • Project

zf create project path
创建新的项目

  • View

zf create view controller-name action-name-or-simple-name
创建View

  • Controller

zf create controller name index-action-included[=1] module
创建Controller

  • Action

zf create action name controller-name[=index] view-included[=1] module

  • Module

zf create module name

  • ProjectProvider

zf create project-provider name actions

解决MySQL server has gone away的问题

Posted in 数据库    作者:Ray    2009年六月8日

今天再汇入一个1GB的 Mysql文件时,突然出现”MySQL server has gone away”的问题,通过google查了一下。原来是MySQL的设置有问题。因为数据库表中有个栏位使用了Longtext(其实使用MediumText也会发生这个错),而MySQL的my.cnf中的max_allowed_packet默认设定值为1M,此时栏位的内容超过了1M的设定值。所以针对这样的错误其实只要修改一下此max_allowed_packet设定值即可。

当修改此设定值为16M时,此错误就不再发生了,可能不需要16M这么大,具体看数据的事件大小即可。

标签:

Drupal 常用模块

Posted in PHP, 网站设计    作者:Ray    2009年五月17日

1. 内容编辑

1.1 BUEditor (http://drupal.org/project/bueditor

bueditor1

1.2 Textile (http://drupal.org/project/textile)

使用自定义的标签来转换成Html文本

1.3 Wysiwyg API (http://drupal.org/project/wysiwyg)

一款所见即所得(WYSIWYG)编辑器。

1.4 FCKeditor (http://drupal.org/project/fckeditor)

另一款所见即所得的编辑器,同时也是较早被Drupal支持,所以维护和支持都不错。

标签:

使用jQuery创建Tooltips

Posted in Javascript, 网站设计    作者:Ray    2009年四月2日

NetTuts最新教材:

Build a Better Tooltip with jQuery Awesomeness

效果如下:

initial-design