问题
I have a number of text files which contain radio programme titles where each item is on a separate line, e.g.:
15 by 15
15 Minute Drama
Adrian Mole
Afternoon Drama
Afternoon Reading
etc
I would like to add double quotes as delimiters to each line, e.g.:
"15 by 15"
"15 Minute Drama"
"Adrian Mole"
"Afternoon Drama"
"Afternoon Reading"
etc
I thought I might be able to do this in Excel but not been able to find a way. I really don't mind whether the solution is Excel based or something else, as long as I don't have to do it manually.
Can anyone help please?
回答1:
This is actually pretty easy in Excel (or any spreadsheet application).
You'll want to use the =CONCATENATE()
function as shown in the formula bar in the following screenshot:
Step 1 involves adding quotes in column B,
Step 2 involves specifying the function and then copying it down column C (by now your spreadsheet should look like the screenshot),
Step 3 (if you need the text outside of the formula) involves copying column C, right-clicking on column D, choosing Paste Special >> Paste Values. Column D should then contain the text that was calculated in column C.
回答2:
Here's a way to do it without formulas or macros:
- Save your CSV as Excel
- Select any cells that might have commas
- Open to the Format menu and click on Cells
- Pick the Custom format
- Enter this => \"@\"
- Click OK
- Save the file as CSV
(from http://www.lenashore.com/2012/04/how-to-add-quotes-to-your-cells-in-excel-automatically/)
回答3:
In Excel for Mac at least, you can do this by saving as "CSV for MS DOS" which adds double quotes for any field which needs them.
回答4:
Double quotes can be achieved using VBA in one of two ways
First one is often the best
"...text..." & Chr(34) & "...text..."
Or the second one, which is more literal
"...text..." & """" & "...text..."
来源:https://stackoverflow.com/questions/25237847/adding-double-quote-delimiters-into-csv-file