创建报告

出自OOo 中文指南手册翻译

跳转到: 导航, 搜索


Reports provide information found in the database in a useful way. In this they are similar to queries. Reports are generated from the database's tables or queries. They can contain all of the fields of the table or query or just a selected group of fields. Reports can be static or dynamic. Static reports contain the data in the selected fields at the time the report was created. Dynamic reports can be updated to show the latest data.

Image:documentation_caution.pngDynamic reports update only the data that is changed or added to a table or query. It does not show any modifications made to a table or query. For example, open the fuel economy query you just created. For the "End-Reading".”Odometer – Fuel.”Odometer” column, change the number 1 to the number 3 after creating the report below. The report will be identical before and after you make the change.
  


For example, a report on vacation expenses divided into categories should probably be a static report because it is based upon specific data that does not change. However, a report on the fuel data should probably be a dynamic report, because this report depends upon data that does change.

Image:documentation_caution.pngAll reports are based upon a single table or query. So you need first to decide what fields you want to use in the report. If you want to use fields from different tables, you must first combine these fields in a single query. Then you can create a report on this query.
  


An example of this caution is creating a report on vacation expenses. Fuel costs are one part of that report as are meal costs. These values are contained in fields of two different tables: Vacations and Fuel. So this report requires creating a query.

Top of page

目录

[编辑] 创建固定格式的报告

我们将创建一个休假费用的报告。在创建该报告前,有些问题需要考虑:

   *在报告中需要哪些信息?
   *在报告中如何排列这些信息?
   *需要哪些字段来提供这些信息?
   *是否将不得不去创建一条查询,由于这些字段在不同的表格中?
   *数据间是否需要运算,在添加到报告之前?

We will create a report on vacation expenses. Certain questions need to be asked before creating the report.

  • What information do we want in the report?
  • How do we want the information arraigned?
  • What fields are required to provide this information?
  • Will a query have to be created because these fields are in different tables?
  • Are there any calculations required in the data before being added to the report?

休假费用包含汽车旅馆费,通行费,杂费,早餐费,午餐费,晚餐费,零食费和燃料费。报告可能只列出各组费用的总计。也可能会列出每天休假费用的总计。还可能会分类列出各组费用的总计。(这将让我们知道支付的费用来自何处。)目前,来处理这样的报告,使用电子表格中的数据查询是最好的方法。在不久的将来,报告特性将包含这些处理功能。

在这里,我们将创建两个报告。第一份报告将列出包括燃料费在内的每天费用。第二份报告将列出每天的燃料成本。

第一个报告,需要从休假表中获得这些字段:日期,汽车旅馆,通行费,早餐,午餐,晚餐,零食,和杂费。这份报告不需要额外的查询。

第二份报告,涉及燃料表。由于这个表格中除了休假期之外,还有其它时间购买的燃料信息,创建的查询仅需要包含在休假期间购买的燃料。

The expenses for our vacation are motel, tolls, miscellaneous, breakfast, lunch, supper, snacks, and fuel. One possible report would simply list the totals of each of these expense groups. Another possible report would list the expense totals for each day of the vacation. A third possible report would list the totals for each expense group for each type of payment. (This would let us know where the money came from to pay the expenses.) At the present time, using the data from the queries in a spreadsheet is the best way to handle reports like this. In the near future, the report feature will include these abilities.

For our purposes, we will create two reports. The first one will list the expenses each day other than fuel. The second report will list the fuel costs each day.

The fields we will need for the first report from the Vacations table are: Date, Motel, Toll, Breakfast, Lunch, Supper, SnackCost, and Miscellaneous. This report will not require an additional query.

The second report involves the Fuel table. Since fuel was purchased and entered into this table at times other than during the vacation, a query needs to be created that contains only the fuel purchased during the vacation.

Top of page


[编辑] 休假表报告

  1. 创建报告。
    1. 点击报告图标,在OpenOffice.org窗口下的汽车数据库列表中。
    2. 在任务列表中,点击使用向导创建报告。将会开启报告向导窗口。
  2. 选择字段。
    1. 选择休假表:表格窗口中或查询下拉列表中。
    2. 点击“>”按钮把这些字段从可用字段列表中转移到报告字段列表中:日期,汽车旅馆,通行费,杂费,早餐,午餐,晚餐,和零食。再点击继续
    3. File:AddFieldsToRpt.png
      Adding fields to a report.
  3. 定义字段标签:确定你需要定义何种字段标签。
    名称较长字段可缩写。点击继续
  4. 这里使用日期来分组,使用“>”按钮把日期字段转移到分组列表中。点击继续
  5. File:Grouping.png
    Grouping list
  6. 排列选项。
    此处不需要任何的额外排列。点击继续
  7. 选择版式。
    此处使用默认版式设定。点击继续
  8. Image:documentation_note.png如果你觉得这样太过于冒险,可以尝试选择其它一些布局选项。选择一个选项后,拖放报告向导窗口,以便您可以看到你所选择结果。(移到鼠标到该窗口的标题栏上,然后拖放。)
      


  9. 创建报告。
    • 定义报告名称:休假费用。
    • 选择固定格式报告。
  10. 点击完成


  1. Create a new report.
    1. Click the Reports icon in the Database list in the Automobile - OpenOffice.org window.
    2. In the Tasks list, click Use Wizard to Create Report. The Report Wizard window opens.
  2. Select the fields.
    1. Select Table: Vacations in the Tables or Queries dropdown list.
    2. Use the > to move these fields from the Available fields list to the Fields in report list: Date, Motel, Tolls, Miscellaneous, Breakfast, Lunch, Supper, and SnackCost. Click Next.
    3. File:AddFieldsToRpt.png
      Adding fields to a report.
  3. Label the fields: answering the question How do you want to label the fields.
    Shorten Miscellaneous to Misc. Click Next.
  4. Since we are grouping by the date, use the > button to move the Date field to the Grouping list. Click Next.
  5. File:Grouping.png
    Grouping list
  6. Sort options.
    We do not want to do any additional sorting. Click Next.
  7. Choose layout.
    We will be using the default settings for the layout. Click Next.
  8. Image:documentation_note.pngIf you feel adventurous, try selecting some of the other layout choices. After selecting a choice, drag and drop the Report Wizard window so that you can see what you have selected. (Move the cursor over the Heading of this window, and then drag and drop.)
      


  9. Create report.
    • Label the report: Vacation Expenses.
    • Select Static report.
  10. Click Finished.

Top of page

[编辑] 休假燃料报告

  1. 创建一条燃料查询,仅包含在休假期间购买的燃料。
    1. 在设计视图中打开查询。
    2. 添加表格,依照步骤2:添加表格使用设计视图创建查询来添加表格。 添加燃料表。
    3. 双击燃料表字清单中的这些字段:日期和燃料成本,并在查询底端输入到表格中。
    4. 在日期字段的条件单元格中,输入以下内容:
    5. BETWEEN #5/25/2007# AND #5/26/2007#
      File:Qcriterion.png
      Setting the criterion for a query.
    6. 保存,命名,然后关闭查询。(推荐名称休假购买燃料
    Image:Tip.png使用日期查询时,输入数据格式是采用 MM/DDYYYY 还是 DD/MM/YYYY,取决于语言中日期的默认设置(此处的默认设置是MM/DD/YYYY)。
    所有日期数据前后必须有一个#。因此,2007年5月25日是写成#05/25/2007# 还是 #25/5/2007#取决于语言中日期的默认设置。
      


  2. 打开一个新的报告。
    1. 右键单击休假购买燃料查询。
    2. 从弹出菜单中选择报表向导
    Image:documentation_note.png当一个新的报告以这种方式打开时,在表格中或查询下拉列表中用来打开报告的查询,就会自动被选中。
      


  3. 创建报告。
    使用>>来移动所有的可用字段报告字段列表中。点击继续
  4. 定义字段名称。
    添加空白字段到燃料成本报告中,并命名为燃料成本。点击继续
  5. 分组字段。
    1. 点击日期字段,高亮显示。
    2. 使用>移动日期字段到群组列表中。点击继续
  6. 选择布局。
    此处布局不作调整。点击继续
  7. 创建报表(完成设置)。
    1. 使用推荐的名称,和查询使用的名称一致。
    2. 选择固定格式报表。点击继续
  1. Create a query containing only fuel bought on the days of the vacation.
    1. Open a query in Design View.
    2. Follow the steps for adding tables in Step 2. Add tables of Using the Design View to create a query. Add the Fuel table.
    3. Double-click these fields in the Fuel table listing: Date and FuelCost to enter them in the table at the bottom of the query.
    4. In the Criterion cell of the Date field, type the following:
    5. BETWEEN #5/25/2007# AND #5/26/2007#
      File:Qcriterion.png
      Setting the criterion for a query.
    6. Save, name, and close the query. (Suggestion: Vacation Fuel Purchases.)
    Image:Tip.pngWhen using dates in a query, enter them in numerical form MM/DDYYYY or DD/MM/YYYY depending upon your language's default setting for dates (my default setting is MM/DD/YYYY).
    All dates must have a # before and after it. Hence, May 25, 2007 is written #05/25/2007# or #25/5/2007depending upon your language's default setting.
      


  2. Open a new report.
    1. Right-click the Vacation Fuel Purchases query.
    2. Select Report Wizard from the context menu.
    Image:documentation_note.pngWhen a new report is opened in this way, the query used to open it is automatically selected in the Tables or Queries dropdown list.
      


  3. Create the report.
    Use >> to move both fields from the Available Fields to the Fields in Report list. Click Next.
  4. Label fields.
    Add a space to FuelCost to make it Fuel Cost (two words). Click Next.
  5. Group fields.
    1. Click Date to highlight it.
    2. Use > to move the Date field to the Groupings list. Click Next.
  6. Choose layout.
    We will be making no changes in the layout. Click Next.
  7. Create report (final settings).
    1. Use the suggested name, which is the same as the query.
    2. Select Static report. Click Finish.

Top of page

[编辑] 创建动态报告

此处将创建一个燃料消耗的统计报告。做到这一点,要修改两个查询:最终读数查询和燃油费用查询。 添加燃料成本字段到最终读数查询。然后,把将燃料成本字段从最终读数查询添加到燃油费用查询。

Image:Tip.png当打开并编辑查询时,会出现如下提示。移动鼠标到黑线上(红色圈中处),它将变成一个双箭头。可以拖放到一个较低的位置。
  


File:QueryEditing.png
Appearance of query when opened for editing.
  1. 添加燃料成本字段到最终读数查询:
    1. 在燃料表格中,双击后添加燃料成本到表格底部。
    2. 保存并关闭查询。
    3. File:AddFieldToQ2.png
      Adding an additional field to the query.
  2. 右键单击最终读数查询并从弹出菜单中选择编辑选项。
  3. 燃料成本字段从最终读数查询添加到燃油费用查询。
    1. 右键单击燃料费用查询并从弹出菜单中选择编辑选项。
    2. 双击最终读数查询列表中的燃料成本添加到表格底部。
  4. 在燃料成本字段的右侧添加一个运算字段。
    1. 在字段单元格中输入:
      最终读数.燃料成本/(最终读数.里程表-燃料.里程表)
    2. 在别名单元格输入如下:
      每英里成本
    Image:documentation_note.png如果使用公制系统,别名则用每公里成本。
      


  5. 保存并关闭查询。
  6. 打开一个新报告。
    右键单击燃料费用查询并选择报表向导
  7. 选择字段。
    使用>>按钮把可用字段列表中的所有字段都移动到报告字段列表中。点击继续
  8. 定义字段名称。
    燃料成本改变为燃料 成本,通过在词组中间添加一个空格。点击继续
  9. 分组字段。
    使用>移动日期字段到群组列表中。点击继续
  10. 排列选项:向导跳过此步。
  11. 选择布局。
    采用默认布局。点击继续
  12. 创建报表。
    1. 改变报告名称为燃料统计。
    2. 默认设定就是动态报告,无须再做改变。
    3. 选择修改报告布局。点击完成

Top of page

We will create a report with some statistics on our fuel consumption. To do this, we have to modify two queries: End-Reading and Fuel Economy. We will be adding the FuelCost field to the End-Reading query. Then we will add the FuelCost field from the End-Reading query to the Fuel Economy query.

Image:Tip.pngWhen opening a query to edit it, it might appear as below. If you move your cursor over the black line (circled in red), it becomes a double headed arrow. Drag and drop it to a lower position.
  


File:QueryEditing.png
Appearance of query when opened for editing.
  1. Add the FuelCost field to the End-Reading query:
    1. In the Fuel table list, double-click to add FuelCost to the bottom table.
    2. Save and close the query.
    3. File:AddFieldToQ2.png
      Adding an additional field to the query.
  2. Right-click the End-Reading query and select Edit from the context menu.
  3. Add the FuelCost field from the End-Reading query to the Fuel Economy query.
    1. Right-click the Fuel Economy query and select Edit from the context menu.
    2. Double-click the FuelCost field in the End-Reading query list to the table at the bottom.
  4. Add a calculation field to the right of the FuelCost field.
    1. Type the following in the Field cell:
      "End-Reading".FuelCost/("End-Reading".Odometer - Fuel.Odometer)
    2. Type the following in the Alias cell:
      cost per mile
    Image:documentation_note.pngIf you use the metric system, cost per km is the appropriate alias.
      


  5. Save and close the query.
  6. Open a new report.
    Right-click the Fuel Economy query and select Report Wizard.
  7. Select fields.
    Move all the fields from the Available fields to the Fields in report list. Use the >> to do so. Click Next.
  8. Label fields.
    Change FuelCost to Fuel Cost by placing a space between the words. Click Next.
  9. Group fields.
    Use > to move the Date field to the Groupings list. Click Next.
  10. Sort options: the wizard skipped this one.
  11. Choose layout.
    Accept the default. Click Next.
  12. Create the report.
    1. Change the report name to Fuel Statistics.
    2. The default setting is Dynamic report, so no change is necessary.
    3. Select Modify report layout. Click Finish.

Top of page

[编辑] 修改报告

在最后一节结尾处,我们离开了以编辑模式打开的燃料统计报告。我们将继续处理这份报告。这些步骤同样可用于任何你需要打开并编辑的报告。

File:BaseRptEdit.png
A report in edit mode.

作者就是在工具>选项> OpenOffice.org>用户数据中列出的名称。日期则是不正确的,该列需要移动到左边,这样看起来更好一些。这些数字都不是正确的,仅为用来显示的小数位数。


Top of page


At the end of the last section, we left the Fuel Statistics report open in the edit mode. We will be working on that report. These same steps can be used with any report that you open for editing.

File:BaseRptEdit.png
A report in edit mode.

The Author is the name you listed in Tools > Options > OpenOffice.org > User Data. The date is not correct. The columns need to be moved to the left to give a better appearance. None of the numbers are correct, but their only purpose is to show the number of decimal places.

Top of page


[编辑] Step 1:改变日期。

  1. 点击日期 (4/26/20)右侧,以便让光标移动到下一字段。使用 Backspace 按键可以清除掉日期。
  2. 插入 >字段 >日期。原始日期处将放置今天的日期。
  3. 改变日期格式:
    1. 双击刚刚插入的日期字段。编辑字段:开启文档窗口 (Figure 91)。
    2. File:BaseEditFields.png
      Figure 91: Modifying a date field.
    3. 这是一份动态报告,因此可以改变选中的字段日期(固定)为日期。
    4. 改变为期望的格式(此处使用 Friday, December 31, 1999)。点击 确认

Top of page


  1. Click to the right of the date (4/26/20) so that the cursor is next to the field. Use the Backspace key to erase the date.
  2. Insert > Fields > Date. This places today's date where the original date was.
  3. Change the date formating:
    1. Double-click the date field you just inserted. The Edit Fields: Document window opens (Figure 91).
    2. File:BaseEditFields.png
      Figure 91: Modifying a date field.
    3. Since this is a dynamic report, change the Select field from Date (fixed) to Date.
    4. Change the Format to what you desire. (I use the Friday, December 31, 1999 choice.) Click OK.

Top of page


[编辑] Step 2:改变列宽度。

列宽度可以通过移动每一列的右边界来改变。光标移动到列的右边框上方后,将变成一个双箭头,然后拖放到你需要的位置。每个列宽度的改变,都不得不在报告的每一个表格中来完成。这个也可以通过右边最后一列来完成,此列并无黑色的边界。如下图所示。

File:RealignCols.png
Realigned columns in a report.

Top of page


The column widths can be changed by moving the cursor over the right border of each column so that it becomes a double-headed arrow. Then drag and drop it where you want it. This has to be done for each column in each table in the report. This can also be done with the last column on the right even though there is no black border. It should now look something like the figure below.

File:RealignCols.png
Realigned columns in a report.

Top of page


[编辑] Step 3: 改变单元格的数字格式。

燃料数量应该有 3位小数。开始,结束,距离应该有一个小数位。燃料成本应该是货币,有两个小数位,而每英里的成本应该有三个小数位。

  1. 右键单击数量单元格,出现弹出菜单。(该单元格在下图中用红色圈中。)
  2. 选择 数字格式
  3. 选项 选区中,
    1. 改变数字为3个小数位。
    2. 点击绿色的复选标记。点击 确认
    3. File:NumberFormat.png
      Option section of the Number Formating window.
  4. 改变每英里成本字段。
    1. 右键单击下面的每英里成本单元格。
    2. 选择数字格式
    3. 在分类列表中,选择货币。点击 确认
  5. 改变燃料成本字段。
    1. 右键单击下面的每英里成本单元格。
    2. 选择 数字格式
    3. 在分类列表中,选择货币。点击 确认
    4. 选项选区中,
      • 改变数字为3个小数位。
      • 点击绿色的复选标记。
    5. 点击 确认

Top of page


The fuel quantity should have three decimal places. The Begin, End, and Distance should have one decimal place. Fuel Cost should be currency and have two decimal places, and Cost per mile should have three decimal places.

  1. Right-click the cell below Quantity to open the context menu. (The cell is circled in red in the figure above.)
  2. Select Number format.
  3. In the Options section,
    1. Change the number of Decimal places to 3.
    2. Click the green checkmark. Click OK.
    3. File:NumberFormat.png
      Option section of the Number Formating window.
  4. Change the Cost per mile field.
    1. Right-click in the cell below Cost per mile.
    2. Select Number Format.
    3. In the Category list, select Currency. Click OK.
  5. Change the Fuel Cost field.
    1. Right-click in the cell below Cost per mile.
    2. Select Number Format.
    3. In the Category list, select Currency.
    4. In the Option section:
      • Set the number of decimal places to 3.
      • Click the green checkmark.
    5. Click OK.

Top of page


[编辑] Step 4: 保存并关闭报告。

双击报告。报告外观如下图所示。

Double-click the report. It should now look like the figure below.

[编辑] 更多创建报告的方式

扩展可用于协助创建报告。Sun报表生成器可以创建时尚,复杂的数据库报表。您可以定义页首群组,页脚群组和计算字段。它可以从[1]获取。

安装扩展,依照下列步骤:

  1. 从菜单中选择 工具 >扩展管理器。在扩展管理器对话框中,点击 从此处获得更多扩展...
  2. OOo扩展的页面在视窗中开启。查找并选择您想要安装的扩展,并按照提示进行安装。在安装过程中,会要求你接受许可协议。
  3. 当安装完成后,扩展会在扩展管理器对话框列表中。


更多有关扩展的信息,请参阅第14章(自定义OpenOffice.org)。


An extension is available to assist in report creation. Sun Report Builder creates stylish, complex database reports. You can define group and page headers, group and page footers, and calculation fields. It is available from [2].

To install this extension, follow these steps:

  1. Select Tools > Extension Manager from the menu bar. In the Extension Manager dialog, click Get more extensions here....
  2. The OOo extensions page opens in your browser window. Find and select the extension you want to install and follow the prompts to install it. During installation, you will be asked to accept a license agreement.
  3. When the installation is complete, the extension is listed in the Extension Manager dialog.

For more about extensions, see Chapter 14 (Customizing OpenOffice.org).

[编辑] 相关链接

本文原文

个人工具