//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); // Please uncomment the following code and ensure you fill in the correct API Endpoint, API Key, and Model Name. //Workbook.AIModelRequestHandler = new OpenAIModelRequestHandler(apiEndpoint, apiKey, modelName); IWorksheet sheet = workbook.Worksheets[0]; sheet.Name = "AI Query Demo"; sheet.Columns[0].ColumnWidth = 57; sheet.Columns[1].ColumnWidth = 20; sheet.Columns[2].ColumnWidth = 48; sheet.Range["A1:C1"].Merge(); sheet.Range["A1"].Value = "Example: Customer Product Reviews and Classification"; sheet.Range["A1"].Font.Bold = true; sheet.Range["A1"].Font.Size = 16; sheet.Range["A1"].Font.Color = Color.White; sheet.Range["A1"].Interior.Color = Color.FromArgb(90, 126, 158); sheet.Range["A1"].HorizontalAlignment = HorizontalAlignment.Center; sheet.Range["A1"].VerticalAlignment = VerticalAlignment.Center; sheet.Range["A1"].RowHeight = 35; sheet.Range["A3"].Value = "Formula:"; sheet.Range["A3"].Font.Bold = true; sheet.Range["A3"].Font.Size = 11; sheet.Range["A3"].Interior.Color = Color.FromArgb(217, 225, 242); sheet.Range["B3"].Value = "=AI.QUERY(\"evaluate these reviews\", A6:A13, \"based on these categories\",B5:C5)"; sheet.Range["B3"].Font.Italic = true; sheet.Range["B3"].Font.Color = Color.FromArgb(68, 114, 196); sheet.Range["A5:C5"].Value = new object[,]{ {"Taco Truck Reviews", "Positive or negative", "Topics"} }; sheet.Range["A5:C5"].Font.Bold = true; sheet.Range["A5:C5"].Interior.Color = Color.FromArgb(155, 194, 230); sheet.Range["A5:C5"].HorizontalAlignment = HorizontalAlignment.Center; sheet.Range["A6:A13"].Value = new object[,]{ {"Great tacos with fresh ingredients! Definitely coming back for more."}, {"The service was slow, but the food was worth the wait."}, {"Not impressed. The tacos were bland and lacked flavor."}, {"Amazing variety of salsas and toppings. Loved it!"}, {"The truck was clean and the staff was friendly."}, {"Overpriced for the portion size. Won't be returning."}, {"The tortillas were soggy and the meat was dry."}, {"Best taco truck in town! Highly recommend the carne asada."} }; sheet.Range["B6"].Formula2 = "=AI.QUERY(\"evaluate these reviews\", A6:A13, \"based on these categories\",B5:C5)"; sheet.Range["A6:C13"].Font.Size = 11; sheet.Range["A6:C13"].HorizontalAlignment = HorizontalAlignment.Center; sheet.Range["A6:C13"].Borders.LineStyle = BorderLineStyle.Medium; sheet.Range["A6:C13"].Borders.Color = Color.FromArgb(200, 200, 200); workbook.Calculate(); // As AI functions operate on an asynchronous computation function, // it is necessary to await the completion of their calculation processes. workbook.WaitForCalculationToFinish(); // Set print settings sheet.PageSetup.FitToPagesTall = 1; sheet.PageSetup.FitToPagesWide = 1; sheet.PageSetup.IsPercentScale = false; sheet.PageSetup.Orientation = PageOrientation.Landscape; // Save to a pdf file workbook.Save("Query.pdf");
' Create a new Workbook Dim workbook As New Workbook ' Please uncomment the following code and ensure you fill in the correct API Endpoint, API Key, and Model Name. ' Workbook.AIModelRequestHandler = New OpenAIModelRequestHandler(apiEndpoint, apiKey, modelName) Dim sheet As IWorksheet = workbook.Worksheets(0) sheet.Name = "AI Query Demo" sheet.Columns(0).ColumnWidth = 57 sheet.Columns(1).ColumnWidth = 20 sheet.Columns(2).ColumnWidth = 48 sheet.Range("A1:C1").Merge() sheet.Range("A1").Value = "Example: Customer Product Reviews and Classification" sheet.Range("A1").Font.Bold = True sheet.Range("A1").Font.Size = 16 sheet.Range("A1").Font.Color = Color.White sheet.Range("A1").Interior.Color = Color.FromArgb(90, 126, 158) sheet.Range("A1").HorizontalAlignment = HorizontalAlignment.Center sheet.Range("A1").VerticalAlignment = VerticalAlignment.Center sheet.Range("A1").RowHeight = 35 sheet.Range("A3").Value = "Formula:" sheet.Range("A3").Font.Bold = True sheet.Range("A3").Font.Size = 11 sheet.Range("A3").Interior.Color = Color.FromArgb(217, 225, 242) sheet.Range("B3").Value = "=AI.QUERY(""evaluate these reviews"", A6:A13, ""based on these categories"",B5:C5)" sheet.Range("B3").Font.Italic = True sheet.Range("B3").Font.Color = Color.FromArgb(68, 114, 196) sheet.Range("A5:C5").Value = New Object(,) { {"Taco Truck Reviews", "Positive or negative", "Topics"} } sheet.Range("A5:C5").Font.Bold = True sheet.Range("A5:C5").Interior.Color = Color.FromArgb(155, 194, 230) sheet.Range("A5:C5").HorizontalAlignment = HorizontalAlignment.Center sheet.Range("A6:A13").Value = New Object(,) { {"Great tacos with fresh ingredients! Definitely coming back for more."}, {"The service was slow, but the food was worth the wait."}, {"Not impressed. The tacos were bland and lacked flavor."}, {"Amazing variety of salsas and toppings. Loved it!"}, {"The truck was clean and the staff was friendly."}, {"Overpriced for the portion size. Won't be returning."}, {"The tortillas were soggy and the meat was dry."}, {"Best taco truck in town! Highly recommend the carne asada."} } sheet.Range("B6").Formula2 = "=AI.QUERY(""evaluate these reviews"", A6:A13, ""based on these categories"",B5:C5)" sheet.Range("A6:C13").Font.Size = 11 sheet.Range("A6:C13").HorizontalAlignment = HorizontalAlignment.Center sheet.Range("A6:C13").Borders.LineStyle = BorderLineStyle.Medium sheet.Range("A6:C13").Borders.Color = Color.FromArgb(200, 200, 200) workbook.Calculate() ' As AI functions operate on an asynchronous computation function, ' it is necessary to await the completion of their calculation processes. workbook.WaitForCalculationToFinish() ' Set print settings sheet.PageSetup.FitToPagesTall = 1 sheet.PageSetup.FitToPagesWide = 1 sheet.PageSetup.IsPercentScale = False sheet.PageSetup.Orientation = PageOrientation.Landscape ' save to a pdf file workbook.Save("Query.pdf")