Login Page - Create Account

Support Board


Date/Time: Sun, 08 Sep 2024 00:46:18 +0000



[Programming Help] - What function in Acsil to use to send data to spreadsheet to specific cell ?

View Count: 166

[2024-06-02 22:14:44]
User384855 - Posts: 5
I'm working on a study that can send the send the data to spreadsheet into specific cell, I can see the data is being send in the message log but its not showing up in the cell, Can anyone Please tell me what function in Acsil can do that ? or even it is Possible ?


Code:


#include "sierrachart.h"

SCDLLName("Send Data to Spreadsheet")

SCSFExport scsf_SendDataToSpreadsheet(SCStudyInterfaceRef sc)
{
SCInputRef Input_Enabled = sc.Input[0];
SCInputRef Input_StudyID = sc.Input[1];
SCInputRef Input_SubgraphIndex = sc.Input[2];
SCInputRef Input_SheetNumber = sc.Input[3];
SCInputRef Input_ColumnIndex = sc.Input[4];
SCInputRef Input_RowOffset = sc.Input[5];
SCInputRef Input_UpdateInterval = sc.Input[6];

if (sc.SetDefaults)
{
sc.GraphName = "Send Data to Spreadsheet";
sc.StudyDescription = "Sends data from a custom study to a spreadsheet";
sc.GraphRegion = 0;

Input_Enabled.Name = "Enabled";
Input_Enabled.SetYesNo(1);

Input_StudyID.Name = "Study ID";
Input_StudyID.SetStudyID(1);

Input_SubgraphIndex.Name = "Subgraph Index";
Input_SubgraphIndex.SetSubgraphIndex(0);

Input_SheetNumber.Name = "Spreadsheet Sheet Number";
Input_SheetNumber.SetInt(1);

Input_ColumnIndex.Name = "Spreadsheet Column Index (1-based)";
Input_ColumnIndex.SetInt(26);

Input_RowOffset.Name = "Spreadsheet Row Offset (0-based)";
Input_RowOffset.SetInt(1);

Input_UpdateInterval.Name = "Update Interval (in seconds)";
Input_UpdateInterval.SetInt(60);

sc.AutoLoop = 1;
sc.FreeDLL = 0;
sc.CalculationPrecedence = LOW_PREC_LEVEL;

return;
}

if (!Input_Enabled.GetYesNo())
return;

int StudyID = Input_StudyID.GetStudyID();
int SubgraphIndex = Input_SubgraphIndex.GetSubgraphIndex();
int SheetNumber = Input_SheetNumber.GetInt();
int SpreadsheetColumnIndex = Input_ColumnIndex.GetInt();
int RowOffset = Input_RowOffset.GetInt();
int UpdateInterval = Input_UpdateInterval.GetInt();

static int LastUpdateTime = 0;
int CurrentTime = sc.GetCurrentDateTime().GetTimeInSeconds();

if ((CurrentTime - LastUpdateTime) < UpdateInterval)
return;

LastUpdateTime = CurrentTime;

SCFloatArray StudySubgraphData;
if (!sc.GetStudyArrayUsingID(StudyID, SubgraphIndex, StudySubgraphData))
{
sc.AddMessageToLog("Error: Unable to retrieve study subgraph data.", 1);
return;
}

int StartIndex = sc.UpdateStartIndex;
int EndIndex = sc.ArraySize;

for (int BarIndex = StartIndex; BarIndex < EndIndex; ++BarIndex)
{
double value = StudySubgraphData[BarIndex];

if (value != 0.0) // Only update non-zero values to reduce unnecessary writes
{
int SpreadsheetRowIndex = BarIndex + RowOffset + 1; // Convert to 1-based index

// Set the value in the spreadsheet
sc.SetSheetCellAsFloat(SheetNumber, SpreadsheetRowIndex, SpreadsheetColumnIndex, (float)value);

// Log the action
char logMessage[256];
snprintf(logMessage, sizeof(logMessage), "Setting value %f at row %d, column %d on sheet %d", value, SpreadsheetRowIndex, SpreadsheetColumnIndex, SheetNumber);
sc.AddMessageToLog(logMessage, 0);
}
}
}

Thanks
Date Time Of Last Edit: 2024-06-03 03:21:56
[2024-07-09 16:41:32]
Userdzungdo - Posts: 3
It's seem impossible.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account