read excel file write new excel file lazarus / 21-General ---------------------------------------------------------------------- rcmz · 2023-12-30 22:10 hi, I have an excel file with a specific format and need to fill the info to specific cel, after I fill the cels need to write to a new excel file. Any sample .pas file or project. TIA rcmz ---------------------------------------------------------------------- wp · 2023-12-30 23:44 First, read the file in a TsWorkbook, workbook.ReadFromFile(filename). Find the worksheet by its name (worksheet := workbook.GetWorksheetByName('...')), or its index (workbook.GetWorksheetByIndex(0)). Then write the new value(s) into the worksheet (e.g. worksheet.WriteNumber(1, 1, 13.456). Finally write the workbook back to file: workbook.WriteToFile(filename, true) (the "true" causes overwriting an already existing file). Sample code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  fspreadsheet, fpsTypes, fpsAllFormats;var  workbook: TsWorkbook;  worksheet: TsWorksheet;begin  workbook := TsWorkbook.Create;  try    workbook.ReadFromFile(AFileName);    worksheet := workbook.GetWorksheetByName('Sheet 1');  // assuming there is a worksheet names "Sheet 1"    worksheet.WriteNumber(1, 2, 13.456);  // writes number 13.456 to cell C2 (row=1, column=2)    // or, to write a text "abc"    // worksheet.WriteText(1, 2, 'abc');    // or to write today's date    // worksheet.WriteDateTime(1, 2, EncodeDate(2023, 12, 31), nfShortDate);   workbook.WriteToFile(AFileName, true);  finally  workbook.Free;  end; ---------------------------------------------------------------------- rcmz · 2023-12-31 01:53 thx for your reply. I have a delphi project that Im converting to Lazarus. in delphi I used the component nExcel, in my delphi file i have a cel that it can have the amount be sum up when filling the file, with this code: Workbook.Sheets[1].Range[sRange,sRange].Value :=                                       Workbook.Sheets[1].Range[sRange,sRange].Value + nSaldo Lazarus code:     I wound need to read the value of the cel and sum it to new amount then after write the new amout something like this ?     worksheet.WriteNumber(1, 2, (worksheet.ReadNumber(1, 2) + 13.456)); TIA rcmz ---------------------------------------------------------------------- wp · 2023-12-31 10:41 Yes, basically correct. One tiny, but important, detail: For historical reasons, the command to read a number from an fpspreadsheet cell is ReadAsNumber rather than ReadNumber. Therefore, your instruction should be written as Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i worksheet.WriterNumber(1, 2, worksheet.ReadAsNumber(1, 2) + 13.345); ---------------------------------------------------------------------- rcmz · 2023-12-31 17:32 Thx, Have a Happy New Year! rcmz ---------------------------------------------------------------------- rcmz · 2023-12-31 18:10 hi again, sorry for this other question How do I acces a sheet in an excel file that haves 7 sheets the info is different for every sheet. TIA Ramiro ps. This is how I do it in Delphi: Workbook.Sheets[7].Range['A'+IntToStr(nRow),'A'+IntToStr(nRow)].Value := dm.Qry1.FieldByName('CUENTA').AsString; Workbook.Sheets[7].Range['B'+IntToStr(nRow),'B'+IntToStr(nRow)].Value := dm.Qry1.FieldByName('DESCRIPCION').AsString; ---------------------------------------------------------------------- wp · 2023-12-31 19:02 Quote from: rcmz on December 31, 2023, 07:10:32 pmhi again, sorry for this other question How do I acces a sheet in an excel file that haves 7 sheets the info is different for every sheet. TIA Ramiro ps. This is how I do it in Delphi: Workbook.Sheets[7].Range['A'+IntToStr(nRow),'A'+IntToStr(nRow)].Value := dm.Qry1.FieldByName('CUENTA').AsString; Workbook.Sheets[7].Range['B'+IntToStr(nRow),'B'+IntToStr(nRow)].Value := dm.Qry1.FieldByName('DESCRIPCION').AsString; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  worksheet := workbook.GetWorksheetByIndex(6);This picks the 7th sheet of the workbook (the index is zero based in FPSpreadsheet). ---------------------------------------------------------------------- rcmz · 2023-12-31 19:52 thx again!!!