Lässt sich eine Datei im csv-Format in Numbers importieren?

Ich möchte eine csv-Datei in ein Blatt einer Numberstabelle importieren, auf einem 2ten Blatt sollen div. Pivot-Tabellen erstellt werden. Die Daten auf dem ersten Blatt sollen regelmäßig via Import einer csv-Datei aktualisiert werden.

MacBook Air 13″, macOS 13.0

Gepostet am 14. Jan. 2023 05:44

Antworten
Frage gekennzeichnet als Höchstrangige Antwort

Gepostet am 14. Jan. 2023 16:23

Hallo outdoor262


vielen Dank für deinen Beitrag / deine Frage in der Apple Support Community. 


Anbei ein funktionales AppleScript (mit Quellenangabe) zum Import von CSV-Files in Numbers. Ich habe einzig das Trennzeichen von "," nach ";" für DE geändert, ggf. sind weitere gewünschte Anpassungen erforderlich.


(* 
Source:  https://discussions.apple.com/thread/252341079?answerId=254431186022#254431186022
old: 	set AppleScript's text item delimiters to ","
new: 	set AppleScript's text item delimiters to ";"
*)

(*Use maximum number of text items to set number of columns, rather than add extra columns on the fly.
I assume this really is a csv file and thus set text item delimiters to ,  *)

set csvFile to (choose file of type "CSV")
set csvText to read csvFile
set AppleScript's text item delimiters to ";"
set rowCount to (count paragraphs in csvText)
set maxColumns to 0
repeat with x from 1 to rowCount
	set columnCount to count text items in paragraph x of csvText
	if columnCount > maxColumns then set maxColumns to columnCount
end repeat

(*

Create new Numbers document, delete  default table, create new table 
based on text item (column) count and paragraph (row) count in csvText.
Set format of all cells to Text:
*)

tell application "Numbers"
	activate
	make new document at front
	tell document 1
		tell sheet 1
			delete every table
			make new table at front with properties ¬
				{row count:rowCount, column count:maxColumns, header column count:0, header row count:0}
			set format of every cell of table 1 to text
		end tell
	end tell
end tell


(*
Loop through paragraphs and delimited items of csvText and place them in the correponding cells in the newly created table
*)

repeat with nextRow from 1 to rowCount
	set columnCount to (count text items in paragraph nextRow of csvText)
	repeat with nextColumn from 1 to columnCount
		set nextValue to text item nextColumn of paragraph nextRow of csvText
		tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
			set nextCell to cell nextColumn of row nextRow
			set value of nextCell to nextValue
		end tell
	end repeat
end repeat


Kopiere den o.g. Code, füge ihn in die App Skripteditor (macOS) ein und starte das Skript.


Ich hoffe, dass ich damit bereits weiterhelfen konnte und wünsche einen schönen Abend / eine gute Nacht.

Liebe Grüße!

2 Antworten
Frage gekennzeichnet als Höchstrangige Antwort

14. Jan. 2023 16:23 als Antwort auf outdoor262

Hallo outdoor262


vielen Dank für deinen Beitrag / deine Frage in der Apple Support Community. 


Anbei ein funktionales AppleScript (mit Quellenangabe) zum Import von CSV-Files in Numbers. Ich habe einzig das Trennzeichen von "," nach ";" für DE geändert, ggf. sind weitere gewünschte Anpassungen erforderlich.


(* 
Source:  https://discussions.apple.com/thread/252341079?answerId=254431186022#254431186022
old: 	set AppleScript's text item delimiters to ","
new: 	set AppleScript's text item delimiters to ";"
*)

(*Use maximum number of text items to set number of columns, rather than add extra columns on the fly.
I assume this really is a csv file and thus set text item delimiters to ,  *)

set csvFile to (choose file of type "CSV")
set csvText to read csvFile
set AppleScript's text item delimiters to ";"
set rowCount to (count paragraphs in csvText)
set maxColumns to 0
repeat with x from 1 to rowCount
	set columnCount to count text items in paragraph x of csvText
	if columnCount > maxColumns then set maxColumns to columnCount
end repeat

(*

Create new Numbers document, delete  default table, create new table 
based on text item (column) count and paragraph (row) count in csvText.
Set format of all cells to Text:
*)

tell application "Numbers"
	activate
	make new document at front
	tell document 1
		tell sheet 1
			delete every table
			make new table at front with properties ¬
				{row count:rowCount, column count:maxColumns, header column count:0, header row count:0}
			set format of every cell of table 1 to text
		end tell
	end tell
end tell


(*
Loop through paragraphs and delimited items of csvText and place them in the correponding cells in the newly created table
*)

repeat with nextRow from 1 to rowCount
	set columnCount to (count text items in paragraph nextRow of csvText)
	repeat with nextColumn from 1 to columnCount
		set nextValue to text item nextColumn of paragraph nextRow of csvText
		tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
			set nextCell to cell nextColumn of row nextRow
			set value of nextCell to nextValue
		end tell
	end repeat
end repeat


Kopiere den o.g. Code, füge ihn in die App Skripteditor (macOS) ein und starte das Skript.


Ich hoffe, dass ich damit bereits weiterhelfen konnte und wünsche einen schönen Abend / eine gute Nacht.

Liebe Grüße!

14. Jan. 2023 15:22 als Antwort auf outdoor262

Hallo outdoor262,

Nein du kannst keine CSV Datei "importieren".


Du kannst diese CSV Datei aber mit Numbers öffnen, Numbers wird dann ein neues Blatte mit dem Inhalt der CSV Datei erzeugen.

Dieses Blatt oder die enthaltene Tabelle kannst du dann in jede existierende Numbers Datei kopieren.

Verwenden von Arbeitsblättern in Numbers auf dem Mac - Apple Support (DE)


Hoffe das hilft.


Ralf

Dieser Thread wurde vom System oder dem Community-Team geschlossen. Du kannst alle Beiträge positiv bewerten, die du hilfreich findest, oder in der Community nach weiteren Antworten suchen.

Lässt sich eine Datei im csv-Format in Numbers importieren?

Willkommen in der Apple Support Community
Ein Forum, in dem Apple-Kunden sich gegenseitig mit ihren Produkten helfen. Melde dich mit deinem Apple Account an, um Mitglied zu werden.