简体   繁体   English

libreoffice基础导入表数据类型问题

[英]libreoffice base import table data type problem

I'm importing a table from LibreOffice Calc to a new embedded Libreoffice base database.我正在将一个表从 LibreOffice Calc 导入到一个新的嵌入式 Libreoffice 基础数据库。 I select the data, copy & paste it, the wizard pops up and I select use first line as column names.我 select 数据,复制并粘贴,弹出向导,我 select 使用第一行作为列名。

I then select all the fields and move to the third step of the import wizard.然后我将 select 的所有字段移至导入向导的第三步。 I can right-click my ID field & make it the primary key, fine.我可以右键单击我的 ID 字段并将其设为主键,很好。 The problem is that if I set the field data types to anything other than double or varchar the import crashes with error "incorrect type for setstring".问题是,如果我将字段数据类型设置为 double 或 varchar 以外的任何类型,导入会崩溃并出现错误“setstring 的类型不正确”。 I want to use integer and date types - how am I supposed to import them?我想使用 integer 和日期类型 - 我应该如何导入它们?

If I leave all fields at either double or varchar and try to edit the table later it won't let me change data types.如果我将所有字段保留为 double 或 varchar 并稍后尝试编辑表,它不会让我更改数据类型。 Same problem if I first define the table and then append records.如果我先定义表然后定义 append 记录,也会出现同样的问题。

This would be easy if I was making a new database from scratch, but I have lots of existing records to import.如果我从头开始创建一个新数据库,这将很容易,但我有很多现有记录要导入。 I need to preserve the keys to set up relationships with other tables.我需要保留与其他表建立关系的键。

I've tried both HSQLDB and firebird embedded.我已经尝试过嵌入 HSQLDB 和 firebird。

This bug stops me from ditching Microsoft Access in favour of libreoffice base.这个错误阻止了我放弃 Microsoft Access 转而使用 libreoffice 基础。 Can anyone suggest a work-around?任何人都可以建议解决方法吗?


Edit编辑

Thank you Jim K for your response, this solves half the problem.谢谢 Jim K 的回复,这解决了一半的问题。

I have found two problematic columns - a date field and a boolean field.我发现了两个有问题的列 - 日期字段和 boolean 字段。 Although Calc does understand that my date field is a date, it crashes the import to Base as described.尽管 Calc 确实知道我的日期字段是一个日期,但它会使导入到 Base 崩溃,如所述。 I then told Calc to display the date as YYYY-MM-DD and the import to Base worked perfectly.然后我告诉 Calc 将日期显示为 YYYY-MM-DD 并且导入到 Base 的工作完美。

The next problem is the boolean (YES/NO) field.下一个问题是 boolean (YES/NO) 字段。 A blank cell in Calc imports OK as boolean false. Calc 中的空白单元格将 OK 导入为 boolean false。 Anything else I tried - YES, NO, TRUE, FALSE, 1, 0 - all crashed the import to base with error message "incorrect type for setstring".我尝试过的其他任何事情 - YES、NO、TRUE、FALSE、1、0 - 都导致导入到 base 时出现错误消息“setstring 的类型不正确”。

Moving boolean data from Base back into Calc shows values as TRUE or FALSE , so it looks like that is what the Base import is expecting.将 boolean 数据从 Base 移回 Calc 将值显示为TRUEFALSE ,因此看起来这是 Base 导入所期望的。 This works correctly for the HSQLDB engine but not for Firebird Embedded.这适用于 HSQLDB 引擎,但不适用于 Firebird Embedded。

The bug has already been reported , so all you need to do is wait for it to be fixed. 该错误已经被报告,所以您需要做的就是等待它被修复。

In the meantime, it's possible to write a Calc macro to read the values from the spreadsheet and run a SQL UPDATE statement to get the correct values into Base.同时,可以编写一个 Calc 宏来读取电子表格中的值并运行 SQL UPDATE语句以将正确的值放入 Base。 My answer here has some code to get started.在这里的回答有一些代码可以开始。

However, there is an easier way.但是,有一种更简单的方法。 Create a temporary Base file that uses HSQLDB and import the data into it from Calc.创建一个使用 HSQLDB 的临时 Base 文件并将数据从 Calc 导入其中。 Then, close Calc and open both the Firebird Embedded and the HSQLDB Base files.然后,关闭 Calc 并打开 Firebird Embedded 和 HSQLDB Base 文件。 Drag the table from the HSQLDB Base window into the other window, which imports seamlessly.将表从 HSQLDB Base window 拖到另一个 window 中,从而无缝导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM