如何插入双引号或单引号

发布于 2024-09-07 18:26:10 字数 1100 浏览 7 评论 0原文

我有一长串名称,需要用引号引起来(可以是双引号或单引号),大约有 8,000 个。我将它们保存在 Excel 中,没有任何引号,我可以复制所有名称并粘贴它们,没有问题,但仍然没有引号。我一直在寻找一个 Excel 公式来为每行中的名称添加引号,但我没有运气。我还尝试了一些巧妙的查找和替换技术,但也没有奏效。我正在寻找的格式是这样的:

“Allen”或“Allen”

其中任何一个都可以。我需要这个,以便我可以将信息存储到数据库中。非常感谢任何帮助。谢谢

PS:

我发现网上其他人需要做我需要做的同样的事情,这个解决方案对他们有用,但我不知道用它做什么:

您可以使用范围来修复它 变量(例如 myCell),然后 用它来迭代“选择” 范围对象的集合,就像这样

Sub AddQuote()
Dim myCell As Range
    For Each myCell In Selection
        If myCell.Value <> "" Then
            myCell.Value = Chr(34) & myCell.Value
        End If
    Next myCell
End Sub

另一个也适用于其他人的解决方案是:

Sub OneUglyExport()

Dim FileToSave, c As Range, OneBigOleString As String

FileToSave = Application.GetSaveAsFilename

Open FileToSave For Output As #1

For Each c In Selection

If Len(c.Text) <> 0 Then _

    OneBigOleString = OneBigOleString & ", " & Chr(34) & Trim(c.Text) & Chr(34)

Next

Print #1, Mid(OneBigOleString, 3, Len(OneBigOleString))

Close #1

End Sub

I have a long list of names that I need to have quotes around (it can be double or single quotes) and I have about 8,000 of them. I have them in Excel without any quotes and I can copy all of the names and paste them no problem but there are still no quotes. I have looked and looked for an Excel formula to add quotes to the name in each row but I have had no luck. I have also tried some clever find and replace techniques but no have worked either. The format I am looking for is this:

"Allen" or 'Allen'

Any of those would work. I need this so I can store the info into a database. Any help is greatly appreciated. Thanks

PS:

I have found other people online needing the same thing done that I need done and this solution has worked for them but I do not know what do with it:

You can fix it by using a range
variable (myCell for example) and then
use that to iterate the 'selection'
collection of range objects, like so

Sub AddQuote()
Dim myCell As Range
    For Each myCell In Selection
        If myCell.Value <> "" Then
            myCell.Value = Chr(34) & myCell.Value
        End If
    Next myCell
End Sub

Another solution that also worked for others was:

Sub OneUglyExport()

Dim FileToSave, c As Range, OneBigOleString As String

FileToSave = Application.GetSaveAsFilename

Open FileToSave For Output As #1

For Each c In Selection

If Len(c.Text) <> 0 Then _

    OneBigOleString = OneBigOleString & ", " & Chr(34) & Trim(c.Text) & Chr(34)

Next

Print #1, Mid(OneBigOleString, 3, Len(OneBigOleString))

Close #1

End Sub

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

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

发布评论

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

评论(7

电影里的梦 2024-09-14 18:26:10

从不带引号的值创建新的带引号的值

  • A 列包含名称。
  • 将以下公式填入B列
    <代码>=“”“”& A1& """"
  • 复制 B 列并选择性粘贴 -> 值

使用自定义函数的

Public Function Enquote(cell As Range, Optional quoteCharacter As String = """") As Variant
    Enquote = quoteCharacter & cell.value & quoteCharacter
End Function

=OfficePersonal.xls!Enquote(A1)

=OfficePersonal.xls!Enquote(A1, "'")

要获取永久带引号的字符串,您需要复制公式值并粘贴特殊值。

To Create New Quoted Values from Unquoted Values

  • Column A contains the names.
  • Put the following formula into Column B
    = """" & A1 & """"
  • Copy Column B and Paste Special -> Values

Using a Custom Function

Public Function Enquote(cell As Range, Optional quoteCharacter As String = """") As Variant
    Enquote = quoteCharacter & cell.value & quoteCharacter
End Function

=OfficePersonal.xls!Enquote(A1)

=OfficePersonal.xls!Enquote(A1, "'")

To get permanent quoted strings, you will have to copy formula values and paste-special-values.

感性 2024-09-14 18:26:10

更简单的步骤:

  1. 突出显示要添加引号的单元格。
  2. 转到格式–>单元格–>自定义
  3. 将以下内容复制/粘贴到类型字段中:\"@\"\'@\'< /代码>
  4. 完成!

Easier steps:

  1. Highlight the cells you want to add the quotes.
  2. Go to Format–>Cells–>Custom
  3. Copy/Paste the following into the Type field: \"@\" or \'@\'
  4. Done!
坏尐絯℡ 2024-09-14 18:26:10

假设您的数据位于 A 列中,请向 B 列添加一个公式

="'" & A1 & "'" 

,然后向下复制该公式。如果您现在保存到 CSV,您应该会获得带引号的值。如果您需要将其保留为 Excel 格式,请复制 B 列,然后粘贴值以删除公式。

Assuming your data is in column A, add a formula to column B

="'" & A1 & "'" 

and copy the formula down. If you now save to CSV, you should get the quoted values. If you need to keep it in Excel format, copy column B then paste value to get rid of the formula.

深海少女心 2024-09-14 18:26:10

为什么不为需要引用的单元格使用自定义格式呢?

如果您为单元格列设置自定义格式,则所有值都将采用该格式。

对于数字......比如邮政编码......这将是这个“#”
对于字符串文本,它将是“@”。

您将文件保存为 csv 格式,并且它将根据需要将所有引号括在单元格数据周围。

Why not just use a custom format for the cell you need to quote?

If you set a custom format to the cell column, all values will take on that format.

For numbers....like a zip code....it would be this '#'
For string text, it would be this '@'

You save the file as csv format, and it will have all the quotes wrapped around the cell data as needed.

岁月染过的梦 2024-09-14 18:26:10

或者选择范围并设置单元格格式>风俗 \”@\”

Or Select range and Format cells > Custom \"@\"

海风掠过北极光 2024-09-14 18:26:10

我想总结一下方法,有超过 4 种方法:

A1 成为要插入引号的单元格。

1.
对于双引号:

=CHAR(34)&A1&CHAR(34)

对于单引号:

=CHAR(39)&A1&CHAR(39)


2 .
=CONCATENATE("'",A1,"'")


3 .
="'"&A1&"'"


4 .应用自定义格式。

假设您有一个号码,并且必须在该号码上插入引号:

在此处输入图像描述

右键单击​​单元格:

然后单击设置单元格格式

在此处输入图像描述

您将得到此屏幕:

在此处输入图像描述

在类型框中写入

'#'

在此处输入图像描述

单击底部的“确定”屏幕。

您将得到结果:

在此处输入图像描述


如果您在单元格中写入了文本,则:

在此处输入图像描述

单击屏幕底部的“确定”

I would like to summarize the methods, there are more than 4 methods:

Let A1 be your cell where you want to insert quotes.

1 .
For Double Quotes:

=CHAR(34)&A1&CHAR(34)

For Single Quotes:

=CHAR(39)&A1&CHAR(39)


2 .
=CONCATENATE("'",A1,"'")


3 .
="'"&A1&"'"


4 . Apply Custom Format.

Suppose you have a number and you have to insert quotes on that number:

enter image description here

Right click the cells:

Then click Format Cells

enter image description here

You will get this screen:

enter image description here

In the Type box write

'#'

enter image description here

Click 'OK' at the bottom of the screen.

You will get the result:

enter image description here


If you have text written in the cell then:

enter image description here

Click 'OK' at the bottom of the screen.

清晰传感 2024-09-14 18:26:10

如果将 Excel 文件另存为 CSV 格式文件,您可能会发现结果很方便插入数据库,尽管我不确定所有字段都会被引用。

If you save the Excel file as a CSV format file, you might find that the result is convenient to inserting into a database, though I'm not sure all of the fields would be quoted.

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