0

I have a not big, but unsolvable for me problem. My Java code connects with smartsheet, and reads a list of sheets at folder (by folder id), next, it copies from folder ony sheets (leaving reports and dashboards), changing name of sheets and paste them at another folder. I'm using Correto 17.

How can I change a value of cell at any sheet by code. I need change only 1 cell for each running code, so it not should be a genius loop. I want to understand the basics of this.

Below I added 2 classes at part after copying and renaming. Everything is working perfect before I trying to change cell. If it will help: cell is unlocked, valueType text_number, not a formula, just text, but in sheet are other cells with values, they are with formulas / they are locked).

I can read a value at cell but can't set it.

public void projectFolderCreate(String projectID_Value) throws SmartsheetException {

 Smartsheet smartsheet = SmartsheetFactory.createDefaultClient(API);
 System.out.println("Folder working. Loading folder: " + getFolderID());

 Folder workFolder = smartsheet.folderResources().getFolder(getFolderID(), null);

for (var element : workFolder.getSheets()) {

System.out.println(element.getId());
ContainerDestination containerDestination = new ContainerDestination().setDestinationType(DestinationType.FOLDER).setDestinationId(8775808614459268L).setNewName(element.getName().replace("Project_Name", projectID_Value));
Sheet sheet = smartsheet.sheetResources().copySheet(element.getId(),containerDestination,EnumSet.of(SheetCopyInclusion.DATA,SheetCopyInclusion.CELLLINKS));
if (sheet.getName().endsWith("Metadata")) {
Sheet newSheet = smartsheet.sheetResources().getSheet(sheet.getId(),null,null,null,null,null,null,null); 
long newSheetId = newSheet.getId(); 
System.out.println("ID of the New Sheet : " + newSheetId); 
Column projIDcolumn = newSheet.getColumns().get(1); 
System.out.println(projIDcolumn.getTitle()); 
Row firstRow = newSheet.getRows().get(2); 
firstRow.getCells().get(2).setValue(new CellDataItem().setObjectValue(projectID_Value)); 
firstRow.getColumnByIndex(projIDcolumn.getIndex()); 
Cell s = newSheet.getRows().get(2).getCells().get(1).setDisplayValue(projectID_Value); 
}System.out.println(sheet.getName() + " was created");
}
}
ProjectFolderWorking(String projectID) throws SQLException, SmartsheetException {     
String folderID;
LikeAWall law = new LikeAWall(1);
DataBase db = new DataBase(law.getPickDB());
db.setApi();
SmartIM smartIM = new SmartIM(db.getApi());
folderID = String.valueOf(SmartIM.getFolderID());
System.out.println("FolderID: " + folderID);
setProjectID(projectID);
smartIM.projectFolderCreate(getProjectID());
}

I'm sure that linking to variable was good, because I tried getters, but setters of this aren't working but compiling without any exceptions / errors / bugs / problems and of coarse result.

Below are the methods I tried.

smartsheet.sheetResources().getSheet(sheet.getId(),null,null,null,null,null,null,null).getRows().get(2).getCells().set(1,null);
smartsheet.sheetResources().getSheet(sheet.getId(),null,null,null,null,null,null,null).getRows().get(2).getCells().get(1).setDisplayValue(projectID_Value)
smartsheet.sheetResources().getSheet(sheet.getId(),null,null,null,null,null,null,null).getRows().get(2).getCells().get(1).setValue(projectID_Value.toString) / and getBytes() 
smartsheet.sheetResources().getSheet(sheet.getId(),null,null,null,null,null,null,null).getRows().get(2).getCells().get(1).setObjectValue()

This is didn't make sense, but I just broke. I tried do every above with parts as:

Sheet sh = lallalalla;
Column s = sh.lalallalala;
Rows w = sh.lalallala;
Cell = w.getCells().get(lalallaa);
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

0 Answers0