Need help with Office Script

Clenny, Natasha 1 Reputation point
2022-02-11T22:27:18.727+00:00

I dont know how to get rid of the error

Type 'string' is not assignable to type '(string | number | boolean)[]'. while running my script even though my fields should all be string and are indicated as string

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
863 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,460 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Clenny, Natasha 1 Reputation point
    2022-02-12T17:20:03.44+00:00

    @Lz._

    This is my script:

     function main(  
          workbook: ExcelScript.Workbook,  
          
          OrderID:string,  
          Date:string,  
          Tech:string,  
          Route:string,  
          ShippingMethod:string,  
          StreetAddress:string,  
          City:string,  
          Reqarray: arrayvar[]  
        )    
          
        { let selectedSheet = workbook.getActiveWorksheet();  
          selectedSheet.getRange("D3").setValue([OrderID]);  
          selectedSheet.getRange("E4").setValue([Date]);  
          selectedSheet.getRange("D7").setValue([ShippingMethod]);  
          selectedSheet.getRange("A3").setValue([Tech]);  
          selectedSheet.getRange("A4").setValue([Route]);  
          selectedSheet.getRange("A5").setValue([StreetAddress]);  
          selectedSheet.getRange("A6").setValue([City]);  
      
          selectedSheet.getRange("A9:E9").setValues([["ItemNumber","Description","ProductCode","VendorNumber","Qty"]]);  
          
          let newTable = workbook.addTable(selectedSheet.getRange("A9:E9"),true);  
          newTable.setName('Items');  
          
          selectedSheet.setName('ReqFormTemplate');  
          
          const starterrow = 2;   
          for (let i=0; i < Reqarray.length; i++) {  
            const currentObject = Reqarray[i];  
            const formattedrow = [[currentObject.ItemNumber,currentObject.Description,currentObject.ProductCode,currentObject.VendorNumber,currentObject.Qty]];  
            const rowRange = `A${starterrow + i}:E${starterrow + i}`;  
            selectedSheet.getRange(rowRange).setValues(formattedrow);  
          }  
          
        }  
          
        interface arrayvar {  
          ItemNumber: string,  
          Description: string,  
          ProductCode: string,  
          VendorNumber: string,  
          Qty: number  
        }  
    
    0 comments No comments