Zum Inhalt springen
AppgineeringAppgineering
Shop
Schreibgeschützt2 Beiträge · 2,674 Aufrufe · Erstellt 02 Jun 2020, 02:44

Update the Spreadsheet - Mission Impossible?

Archiviert: Diskussion auf Discord verlagertDiscord
Leandro V.Ursprünglicher Verfasser
#1

Hi Nick!

I saw an old post about update Spreadsheet in ATVO Theme and I started to code some stuff to understand how it works.
So, here is my Spreadsheet inside the project content:

View image on i.ibb.co

And here is the content:

View image on i.ibb.co

My code is trying to do a simple update in column[1] and save the spreadsheet:

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data;
using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace Scripts
{
	public class test : IScript
	{
		public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
		{
			var sheet = item.Theme.Spreadsheets.Find("datasetLe.csv").Table.Data.Copy();
			DataRow data = null;

			foreach(DataRow row in sheet.Rows)
			{
				if((int)row[0] == 1234)
				{
					data = row;
					data[1] = "QWERTY";
				}
			}

			item.Theme.Spreadsheets.Find("datasetLe.csv").Table.Data.Clear();
			item.Theme.Spreadsheets.Find("datasetLe.csv").Table.Data.Load(sheet.CreateDataReader());
			item.Theme.Spreadsheets.Find("datasetLe.csv").Table.Data.AcceptChanges();

			Console.WriteLine("Teste!!!");
			return "";
		}

	}
}

Testing the code, I got no errors and the Spreadsheet updated(?):

View image on i.ibb.co

Checking the file inside the project folder:

View image on i.ibb.co

So, I closed the ATVO Theme Editor and opened it again and checked the content of the Spreadsheet in the editor:

View image on i.ibb.co

Well.. Is it possible to update the file? What is wrong in my code?

Thanks!

Nick ThissenAppgineering
#2

You're only updating the spreadsheet in memory, never saving it back to the file.

Dieser Thread ist archiviert.

Neue Antworten finden auf Discord statt.

Auf Discord weiterlesen