【发布时间】:2012-08-03 07:04:48
【问题描述】:
2012/08/31 : 更新了我的帖子
在整个网络上搜索它,找到了一些片段,但没有任何帮助,所以我求助于你。
环境信息:
编程语言是 VBA / Access 2003
将从现有的“.ini”文件中读取数据
数据应插入Access数据库
现在我的问题:
我有一个 ini 文件,其中包含 ini 文件中的信息。该文件如下所示:
[product_details]
product_description=my product description
product_name=my product
product_price=11.0
product_sku=myproduct2012
这些信息保存在“products.ini”中,当在记事本或记事本++中打开时,它会正确显示并可以插入到我的访问数据库中,我可以在我的表单中显示这些信息
但现在有人想要这样的东西:
[product_details]
product_description=мое описание продукта
product_name=мой продукт
product_price=11.0
product_sku=произведение2012
当通过 GetINIValue 加载这些信息时,值将作为不可读的文本保存到数据库中。
编辑:在记事本/记事本++中也显示正确,因此西里尔字符被正确传输到ini文件中
我确实尝试了很多东西(使用 UNICODE 版本的 GetINIValue,获取字符代码等,检查西里尔文文本)没有任何帮助。
它应该做什么: 无论是什么语言,我都需要帮助才能从这个 ini 条目中获取值(在这种情况下,英语、德语、法语、俄语就足够了)
希望有人可以帮助我。
编辑:我已经尝试使用此代码和平的 Remou 的测试,通过以下方式打开它:
Dim SQL As String
Dim strValue As String
strValue = GetValueOf("product_details","product_description","C:\cyrillic.txt")
SQL = "UPDATE [products] SET [product_description]='" & strValue & "' WHERE [product_id]=23;"
CurrentDb.Execute SQL,dbseechanges
这是我的函数代码,用于读出我需要的特定行:
Public Function GetValueOf(ByVal Section As String, ByVal Entry As String, ByVal File As String)
Dim fs As New FileSystemObject
Dim ts As TextStream
Dim temp As String
Dim response As String
Dim intresponses As String
Dim SectionFoundBegin As Boolean
Dim SectionFoundEnd As Boolean
Dim DoNext As Boolean
Dim Parse() As String
Dim Finished As Boolean
SectionFoundBegin = False
SectionFoundEnd = False
Set ts = fs.OpenTextFile(File, ForReading, , TristateTrue)
response = ""
intresponses = 1
Finished = False
Do
DoNext = False
temp = ts.ReadLine
If (Not Finished) Then
If (temp = "[" & Section & "]") And Not DoNext Then
SectionFoundBegin = True
DoNext = True
End If
If ((InStr(1, temp, "[") > 0) And (SectionFoundBegin)) And Not DoNext Then
SectionFoundEnd = True
DoNext = True
End If
If (SectionFoundBegin And Not SectionFoundEnd) And Not DoNext Then
If (InStr(1, temp, "=") > 0) Then
Parse = Split(temp, "=")
If (Parse(0) = Entry) Then
While (intresponses <= UBound(Parse))
response = response + Parse(intresponses)
intresponses = intresponses + 1
Wend
DoNext = True
Else
DoNext = True
End If
Else
DoNext = True
End If
End If
End If
Loop Until ts.AtEndOfStream
GetValueOf = response
End Function
我需要什么: 类似的东西:
"UPDATE [products] SET [product_description]='мое описание продукта' WHERE [product_id]=23;"
我得到了什么:
"UPDATE [products] SET [product_description]='??? ???????? ????????' WHERE [product_id]=23;"
更新: 那么现在我真的是你的帮助:
我已插入以下代码:
Public Function GetUnicodeValueOf(ByVal Section As String, ByVal Entry As String, ByVal File As String)
Dim fs As Object
Dim ts As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim temp As String
Dim strResponse As String
Dim intResponses As Integer
Dim SectionFoundBegin As Boolean
Dim SectionFoundEnd As Boolean
Dim DoNext As Boolean
Dim Parse() As String
Dim Finished As Boolean
On Error GoTo Error_GetUnicodeValueOf
SectionFoundBegin = False
SectionFoundEnd = False
Set ts = fs.OpenTextFile(File, ForReading, , TristateTrue)
strResponse = ""
intResponses = 1
Finished = False
Do
DoNext = False
temp = ts.ReadLine
If (Not Finished) Then
If (temp = "[" & Section & "]") And Not DoNext Then
SectionFoundBegin = True
DoNext = True
End If
If ((InStr(1, temp, "[") > 0) And (SectionFoundBegin)) And Not DoNext Then
SectionFoundEnd = True
DoNext = True
End If
If (SectionFoundBegin And Not SectionFoundEnd) And Not DoNext Then
If (InStr(1, temp, "=") > 0) Then
Parse = Split(temp, "=")
If (Parse(0) = Entry) Then
While (intResponses <= UBound(Parse))
strResponse = strResponse + Parse(intResponses)
intResponses = intResponses + 1
Finished = True
Wend
DoNext = True
Else
DoNext = True
End If
Else
DoNext = True
End If
End If
End If
Loop Until ts.AtEndOfStream
Exit_GetUnicodeValueOf:
GetUnicodeValueOf = strResponse
Exit Function
Error_GetUnicodeValueOf:
ActionLogging "Fehler beim Parsen der Datei '" & File & "'"
Resume Exit_GetUnicodeValueOf
End Function
在我的硬盘上使用这个文件(保存为 UTF-8 没有 BOM):
[product_details]
manufacturer_name=
product_id=50
sku=BU-01722
set=4
type=simple
type_id=simple
color=11
ean=
name=Колесникова
description=[LANGTEXT] Колесникова Е.В Я считаю до двадцати [Рабочая тетрадь] 6-7л
short_description=[KURZTEXT] Колесникова Е.В
old_id=
weight=1.0000
news_from_date=
news_to_date=
status=1
url_key=kolesnikova
url_path=kolesnikova.html
visibility=4
gift_message_available=2
required_options=0
has_options=0
image_label=
small_image_label=
thumbnail_label=
created_at=2012-06-25 07:58:29
updated_at=2012-07-27 09:06:24
price=2.0000
special_price=
special_from_date=
special_to_date=
cost=
tax_class_id=2
minimal_price=
enable_googlecheckout=1
meta_title=
meta_keyword=
meta_description=
is_recurring=0
recurring_profile=
custom_design=
custom_design_from=
custom_design_to=
custom_layout_update=
page_layout=
options_container=container2
我需要:
[LANGTEXT] Колесникова Е.В Я считаю до двадцати [Рабочая тетрадь] 6-7л
来自 INI-Key:描述
进入我的访问数据库。
首先它可以正常工作,但现在当我加载使用“TriStateTrue”保存的文件时 一切都结束了:?????????????????????????????????????????? 一行。
使用 TriStateMixed,除了西里尔字母之外的所有内容都可以很好地解析 КолеÑник¡¾Ð²Ð° Е.Ð' Я ÑчиÑ,аю до двадцаÑ,и [Ð Ð°Ð±Ð¾Ñ‡Ð°Ñ Ñ,еÑ,радь] 6-7л
我搜索了源代码,没有发现错误。
FILE is UTF-8 without BOM (coming from selfwritten Web API for Magento)
Using Access 2003
Need to get Cyrillic Text into my Database where also German / English Texts could be inside the File
【问题讨论】:
-
你是怎么看这篇文章的?如果我运行
Dim fs As New FileSystemObject: Dim ts As TextStream: Set ts = fs.OpenTextFile("z:\docs\info.ini", ForReading, , TristateTrue): Screen.ActiveControl = ts.ReadAll我的示例表单上的文本控件将包含您所显示的内容。注意TristateTrue,表示以 unicode 格式打开。 ` -
我们可以假设 .ini 文件在文件系统上保存为 UTF-8 或 UNICODE 文本文件而不是 ASCII 文件吗? (“另存为”对话框中的“编码”字段...)
-
感谢您的回答,将测试您的解决方案@Remou。是的,文件保存为 php 脚本的回显响应,为 UTF-8 文件。访问函数向 php 文件发送一个请求,该文件以 INI 文件样式返回“渲染”的结果,我可以通过“GetINIValue”轻松打开该文件并将它们发送到我的数据库中。我打开一个记录集,说我希望我的字段“product_name”应该由 GetINIValue("product_details","product_name","filename.ini") 填充。这适用于德语和英语,但不适用于西里尔字符。我必须先将它们保存到我的数据库中,然后才能在屏幕上显示它们。
-
我编辑了我的帖子并使用我测试过的方法添加了源代码@Remou,不幸的是,这并没有导致正在考虑的结果。也许我只是那里的一个小错误。如果有人能再看看这个就好了。我必须将西里尔字符存储在数据库中。如果数据存储在以西里尔字母编写的数据库中,则所有内容都可以正确显示,因此显示它们不是问题。缺少的只是从文件中读取以及将数据存储在数据库中
-
我完全按照在我的 PC 上编写的代码测试了您的代码,最终在数据库中使用了 Cryllic。我在英语语言环境中使用 Windows 7 和 Access 2010。