2010年04月28日


package cn.com.hrbb.samples;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

/**
*
* 演示使用 JACOB : Java COM Bridge 操纵 Word 文档
*
* 作者:高宏伟(DukeJoe)
* 时间:2010-04-28 15:49:34
* 地点:北京市朝阳区光华路甲8号和乔大厦10楼哈尔滨银行
* JDK: 1.6.0_17
* 环境版本:Windows XP Home Edition Service Pack 3
* Office 2007
* jacob-1.14.3
* QQ: 21807822
* E-MAIL: dukejoe@163.com
* 关键字: JACOB Word
* 注释:主要演示功能,增加文字内容,表格,及如何操纵表格
*
*/

public class Test1
{

    private ActiveXComponent objWord;
    private Dispatch document;

    private Dispatch wordObject;

    public static void main(String[] args)
    {
        Test1 t1 = new Test1();

        try
        {
            // 为了演示方便,请在下列目录新建一个空白文档
            t1.open(“c:\\java_dev\\test1.docx”);

            t1.close();
        } catch (Exception e)
        {
            t1.close();
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }

    public void open(String filename)
    {
        // 实例化 objWord
        objWord = new ActiveXComponent(“Word.Application”);

        // 将本地word对象赋到 wordObject上
        wordObject = objWord.getObject();

        // 使 word 为“可见”,主要是方便调试。正式应用时,把true改为false
        Dispatch.put(wordObject, “Visible”, new Variant(true));

        // 获得Documents对象
        Dispatch documents = objWord.getProperty(“Documents”).toDispatch();

        // 调用 Open 打开 Document
        document = Dispatch.call(documents, “Open”, filename).toDispatch();

        // 演示如何增加文字内容
        Dispatch disSelect;
        disSelect = Dispatch.call(objWord, “Selection”).toDispatch();
        Dispatch.call(disSelect, “TypeText”, “高宏伟”);
        Dispatch.call(disSelect, “TypeParagraph”);
        Dispatch.call(disSelect, “TypeText”, “QQ:21807822″);
        Dispatch.call(disSelect, “TypeParagraph”);
        Dispatch.call(disSelect, “TypeText”, “e-mail:dukejoe@163.com”);

        // 演示如何增加表格
        Dispatch disTables;
        disTables = Dispatch.call(document, “Tables”).toDispatch();
        Dispatch disRange;
        disRange = Dispatch.call(disSelect, “Range”).toDispatch();
        Dispatch.call(disTables, “Add”, disRange, 3, 4, 1);

        Dispatch disTable;
        disTable = Dispatch.call(disTables, “Item”, 1).toDispatch();
        Dispatch.put(disTable, “ApplyStyleColumnBands”, 1);

        // 演示如何操纵表格,比如设置对齐为“居中”
        // Unit : 5–wdLine 1–wdCharacter
        // Extend : 2–wdExtend
        Dispatch.call(disSelect, “MoveDown”, 5, 2, 2);
        Dispatch.call(disSelect, “MoveRight”, 1, 3, 2);
        Dispatch disParagraphFormat;
        disParagraphFormat = Dispatch.get(disSelect, “ParagraphFormat”)
                .toDispatch();
        Dispatch.put(disParagraphFormat, “Alignment”, 1);

        Dispatch.call(disSelect, “MoveDown”, 5, 1);
        Dispatch.call(disSelect, “TypeParagraph”);
        Dispatch.call(disSelect, “TypeText”, “黑龙江省哈尔滨市”);
        Dispatch.call(disSelect, “TypeParagraph”);
        Dispatch.call(disSelect, “TypeText”, “哈尔滨银行”);
        Dispatch.call(disSelect, “TypeParagraph”);
    }

    public void close()
    {
        // 关闭文档
        // 由于是演示程序,这里只简单的把word退出即可
        Dispatch.call(document, “Close”);
        Dispatch.call(wordObject, “quit”);
    }
}

2009年12月04日

首先说明一下我的环境:

Windows XP Home Edition SP3
MySQL 5.1.41 win32 ZIP 非安装版
MySQL GUI Tools 5.0(版本1.2.17.0)

运行MySQLAdministrator时提示:
服务器服务或配置文件不能找到。启动参数和服务节因此不可用。
Either the server service or the configuration file could not be found. Startup variables and service section are therefore disabled

我的解决办法如下:

C:\mysql-5.1.41-win32\bin>mysqld –install MySQL –defaults-file=c:\my.ini
Service successfully installed.

C:\mysql-5.1.41-win32\bin>net start MySQL
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

C:\mysql-5.1.41-win32\bin>

1、通过执行mysqld –install命令可以安装MySQL服务,同时指定配置文件my.ini的位置
2、通过执行net start 命令,启动MySQL服务
这时你再运行MySQLAdministrator时,就不会再报错了。

如果还有什么问题,可以先检查一下您的环境是否与我一致,或者与有联系。
QQ:21807822
E-Mail:dukejoe@163.com
高宏伟
黑龙江省哈尔滨市动力区

其它比较有用的信息,也可以参考一下。

mysqld –verbose –help 查看帮助
删除MySQL服务

C:\mysql-5.1.41-win32\bin>mysqld –remove MySQL
停止MySQL服务
net stop MySQL