cocoa 中 excel 到 plist 的转换,反之亦然

发布于 2024-10-15 16:55:11 字数 686 浏览 2 评论 0原文

我想从 Excel 文件创建 plist 文件。定义了excel和plist的结构。 Excel文件只有两列,一列是“键”,另一列是对应的“值”列。 因此,将生成的最终 plist 的形式如下:

<key>keyString1</key>
<string>valueString1</string>
<key>keyString2</key>
<string>valueString2</string> 
<key>keyString3</key>
<string>valueString3</string>   
.............................
.............................
.............................
<key>keyStringn</key>
<string>valueStringn</string>

现在的问题是“keys”和“values”的字符串值是反过来的字符串,即它们不是一个单词字符串。它们可能会超过一行。因此我不能在这里使用 csv 文件结构。

需要您的紧急帮助。

请建议如何从 Excel 工作表中读取值,以便可以分隔两列值。任何示例代码都会提供帮助。

I want to create a plist file from an excel file. The structure of excel and plist is defined.
Excel file has only two columns, one is "key" and the other is corresponding "value" column.
So the final plist that will be generated is of the form:

<key>keyString1</key>
<string>valueString1</string>
<key>keyString2</key>
<string>valueString2</string> 
<key>keyString3</key>
<string>valueString3</string>   
.............................
.............................
.............................
<key>keyStringn</key>
<string>valueStringn</string>

Now the problem is that the string values for "keys" and "values" are inturn strings i.e. they are not one word string. They may go more than one line.Hence I can't use csv file structure here.

Need your urgent help.

Please suggest how to read values from excel sheet so that both column values can be separated.Any sample code will add aid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月静好 2024-10-22 16:55:11

我通过在 Excel 中编写公式来为您创建 plist 文件的文本来完成此操作。这很容易。

1)(可选) 在 XCode 中,创建一个具有最终所需格式的 plist。保存,然后在 Finder 中转到此内容。在 textWrangler 或文本编辑器中打开它,以便您可以查看 plist 中每个元素的标签。

例如,您应该找到类似以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

<dict>

    <key>First Key Name</key>
    <array>
        <string>Before God we are all equally wise</string>
        <string></string>
        <string>Albert Einstein</string>
        <integer>0</integer>
    </array>

    <key>Second Key Name</key>
    <array>
        <string>Do not worry about your troubles.</string>
        <string></string>
        <string>Albert Einstein</string>
        <integer>0</integer>
    </array>

</dict>
</plist>

2) 我假设:
- 您的电子表格代表了许多行/对象/级别的相同 4 个属性的描述
- 您将每个数组作为电子表格中的单独行
- 以相同的顺序为每一行描述相同的属性。
- 您将能够通过知道它们存储在哪个索引来访问数组中的项目。即,我将通过查看索引 2 处的第二个数组来获取第二个作者。

您的电子表格应如下所示:

           A                B            C             D                E            F

     /--(Key Names)--\/-------------------(Properties of Each)-----------------\

1    Level Name      |   Quote        |  Notes  |   Author        |  Favorited  | 
     ____________________________________________________________________________
2    First Key Name  |  Before God... |         | Albert Einstein |      0      |
3    Second Key Name |  Do not wor... |         | Albert Einstein |      0      |
.
.
.

因此,我的每个对象都将在我的字典中获得自己的键,并且每个对象由 3 个字符串和一个整数描述。

3) 公式

在电子表格最后一列的右侧,我将编写一个公式来生成该行的 xml 代码:

(F2) = CONCATENATE ("<key>",A2,"</key> <array> <string>",B2,"</string> <string>",C2,"</string> <string>",D2,"</string> <integer>",E2,"</integer> </array>")

将此单元格的右下角向下拖动到所有其他单元格中行,它们将自动填充每行的信息。

同样,在电子表格底部的所有行下,您可以使用另一个公式来连接行。假设您有 300 行:

(F4) = CONCATENATE (F2:F300) 

现在将此数据复制到文本文件中,并添加最后几个标签和文档类型信息,您可以从上面复制这些信息。使用扩展名 .plist 保存,然后就可以开始了!将文件添加回您的 xcode 项目并像任何其他 plist 一样加载它。

I accomplished this by writing a formula in excel to create the text of the plist file for you. Its pretty easy.

1) (optional) In XCode, create a plist that has the formatting you want in the end. Save, and go to this in finder. Open it in textWrangler or text edit so that you can see what the tags are for each element in your plist.

For example, you should find something like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

<dict>

    <key>First Key Name</key>
    <array>
        <string>Before God we are all equally wise</string>
        <string></string>
        <string>Albert Einstein</string>
        <integer>0</integer>
    </array>

    <key>Second Key Name</key>
    <array>
        <string>Do not worry about your troubles.</string>
        <string></string>
        <string>Albert Einstein</string>
        <integer>0</integer>
    </array>

</dict>
</plist>

2) I will assume:
- Your spreadsheet represents a description of the same 4 properties for many rows/Objects/Levels
- You have each array as a separate row in your spreadsheet
- The same properties are being described for every row in the same order.
- You will be able to access the items in the array by knowing which index they are stored at. ie, I would get the second Author by looking in the second array at index 2.

Your spreadsheet should look something like this:

           A                B            C             D                E            F

     /--(Key Names)--\/-------------------(Properties of Each)-----------------\

1    Level Name      |   Quote        |  Notes  |   Author        |  Favorited  | 
     ____________________________________________________________________________
2    First Key Name  |  Before God... |         | Albert Einstein |      0      |
3    Second Key Name |  Do not wor... |         | Albert Einstein |      0      |
.
.
.

So each of my objects will get its own key in my dictionary and each object is described by 3 Strings and an integer.

3) The Formula

On the right of the last column in my spreadsheet, I will write a formula that generates the xml code for that row:

(F2) = CONCATENATE ("<key>",A2,"</key> <array> <string>",B2,"</string> <string>",C2,"</string> <string>",D2,"</string> <integer>",E2,"</integer> </array>")

Drag the lower-right corner of this cell down into all the other rows and they will automatically populate the information for each row.

Similarly, at the bottom of the spreadsheet, under all the rows you can use another formula to concatenate the rows. Say you had 300 rows:

(F4) = CONCATENATE (F2:F300) 

Now copy this data into an text file, and add the last few tags and doctype information, which you can copy from above. save with the extension .plist and you're good to go! Add the file back into your xcode project and load it like any other plist.

匿名。 2024-10-22 16:55:11

要将数据从 Excel 导出到文本文件,请使用“另存为”命令。

有两种常用的文本文件格式:

定界文本文件 (.txt),其中 TAB 字符(ASCII 字符代码 009)通常分隔每个文本字段。

逗号分隔值文本文件 (.csv),其中逗号字符 (,) 通常分隔每个文本字段。

您可以更改使用的分隔符。

http://office.microsoft.com/en-us/excel-help/import-or-export-text-txt-or-csv-files-HP010099725.aspx#BMchange_the_delimiter_that_is_used_in_

To export data from Excel to a text file, use the Save As command.

There are two commonly used text file formats:

Delimited text files (.txt), in which the TAB character (ASCII character code 009) typically separates each field of text.

Comma separated values text files (.csv), in which the comma character (,) typically separates each field of text.

You can change the separator character that is used.

http://office.microsoft.com/en-us/excel-help/import-or-export-text-txt-or-csv-files-HP010099725.aspx#BMchange_the_delimiter_that_is_used_in_

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文