How to add lines to an Excel file? lazarus / 49-FPSpreadsheet ---------------------------------------------------------------------- DarkNem · 2015-10-23 09:01 Can anyone help me please with FPSpreadsheet? Im trying to make a log file for something, and i cant add lines to an existing excel file 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  MyWorkbook := TsWorkbook.Create; MyWorkbook.SetDefaultFont('Calibri', 11);   MyWorksheet := MyWorkbook.AddWorksheet('Журнал');   MyWorksheet.WriteUTF8Text(0, 0, 'Дата записи');  MyWorksheet.WriteUTF8Text(0, 1, 'Время записи');  MyWorksheet.WriteUTF8Text(0, 2, 'Метка');  MyWorksheet.WriteUTF8Text(0, 3, 'Тип карты');  MyWorksheet.WriteUTF8Text(0, 4, 'Тип записи');   MyWorksheet.WriteBorders(0, 0, [cbNorth, cbEast, cbSouth, cbWest]);  MyWorksheet.WriteBorders(0, 1, [cbNorth, cbEast, cbSouth, cbWest]);  MyWorksheet.WriteBorders(0, 2, [cbNorth, cbEast, cbSouth, cbWest]);  MyWorksheet.WriteBorders(0, 3, [cbNorth, cbEast, cbSouth, cbWest]);  MyWorksheet.WriteBorders(0, 4, [cbNorth, cbEast, cbSouth, cbWest]);   MyWorksheet.WriteColWidth(0, 16);  MyWorksheet.WriteColWidth(1, 16);  MyWorksheet.WriteColWidth(2, 10);  MyWorksheet.WriteColWidth(3, 20);  MyWorksheet.WriteColWidth(4, 20);   MyWorksheet.WriteDateTime(MyWorksheet.GetLastOccupiedRowIndex+1, 0, now, nfShortDate);  MyWorksheet.WriteDateTime(MyWorksheet.GetLastOccupiedRowIndex, 1, now, nfShortTime);  MyWorksheet.WriteUTF8Text(MyWorksheet.GetLastOccupiedRowIndex, 2, '6173');  MyWorksheet.WriteUTF8Text(MyWorksheet.GetLastOccupiedRowIndex, 3, 'SD- Карта');  MyWorksheet.WriteUTF8Text(MyWorksheet.GetLastOccupiedRowIndex, 4, 'Обычная');   MyWorkbook.WriteToFile(ExtractFilePath(ParamStr(0)) + 'test.xls', sfExcel8, true);  MyWorkbook.Free; ---------------------------------------------------------------------- wp · 2015-10-23 09:32 Your code is working here. What is wrong? You say that you cannot add lines to an EXISTING excel file. Your example always creates a NEW file. To modify an existing file you have to load it first (MyWorkbook.ReadFromFile), modify it, and write it back. But be warned: fpspreadsheet does not support all features available in Excel files, therefore you must expect some loss of formatting or special features this way. Or do you want only horizontal lines? In this case only use [cbSouth] in the WriteBorders procedure, it draws only the bottom border line of the specified cell. ---------------------------------------------------------------------- DarkNem · 2015-10-23 10:35 Quote from: wp on October 23, 2015, 11:32:52 amYour code is working here. What is wrong? You say that you cannot add lines to an EXISTING excel file. Your example always creates a NEW file. To modify an existing file you have to load it first (MyWorkbook.ReadFromFile), modify it, and write it back. But be warned: fpspreadsheet does not support all features available in Excel files, therefore you must expect some loss of formatting or special features this way. Oh, i see now. Do you have a working example for what im looking for? I havent worked with that, but i will try figure out how, but im not sure how to do it ._. Thanks by the way. ---------------------------------------------------------------------- wp · 2015-10-23 10:47 Something like this (not tested): 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 procedure AddHorLinesToWorksheet(AFilename: String; ASheetIndex: Integer;  ARows: array of integer);var  MyWorkbook: TsWorkbook;  MyWorksheet: TsWorksheet;  i, c: Integer;begin  MyWorkbook := TsWorkbook.Create;   // Read existing file  MyWorkbook.ReadFromFile(AFilename);   // Get the worksheet to be modified  MyWorksheet := MyWorkbook.GetWorksheetbyIndex(ASheetIndex);   // Add the border flag for all rows specified in ARows.  // The border will be drawn at the bottom of the cells  for i := 0 to High(ARows) do    for c := 0 to MyWorksheet.GetLastOccupiedColIndex do      MyWorksheet.WriteBorders(ARows[i], c, [cbSouth]);   // Write file back to disk  // modify the filename a bit to keep the original file (append "modified")  // otherwise unsupported features will be destroyed by fpspreadsheet  AFileName := ChangeFileExt(AFileName, '')+'_modified' + ExtractFileExt(AFileName);  MyWorkbook.WriteToFile(AFilename, MyWorkbook.FileFormat);    // Destroy the workbook  MyWorkbook.Free;end; ---------------------------------------------------------------------- DarkNem · 2015-10-27 10:46 It appears to be working, much thanks :DD