How to upload and then open ms-word or ms-excel files


If you wish to leave comments or ask questions, please log on or sign up.

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Nov 10, 2011
Company: 1A Software e.U

Hello!

I can upload PDF-Files into 1C-Application and then open them but do not know how does it work with MS-Word or MS-Excel files.
Thank you in advance for every advice!

Regards,
Lioudmila

 
#2
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Jan 10, 2019
Company: 1c developer

Hello, Lioudmila,

There are several ways to import data from Word and Excel files into 1C. The most common is - using of COM Objects. In the case of Excel tables, I often use this way (using SpreadSheetDocument instead of COM-object):

FileOpenDialog = new FileDialog(FileDialogMode.Open);
FileOpenDialog.Filter = "Excel sheet 97 (*.xls)|*.xls|Excel workbook (*.xlsx)|*xlsx";
FileOpenDialog.Multiselect = False;
FileOpenDialog.Title = "Choose Excel file to open";

If FileOpenDialog.Choose() Then
// --- Parsing choosed file
ExcelFileName = FileOpenDialog.FullFileName;
TableDoc = new SpreadsheetDocument;
TableDoc.Read(ExcelFileName);
LinesCount = TableDoc.PageHeight;

LineNumber = 1;
ColNumber = 1;

While LineNumber <= LinesCount Do
Value = TableDoc.Area(LineNumber, ColNumber).Text; //you can use .Value property also
Message(Value);
LineNumber = LineNumber + 1;
EndDo

EndIf;


it works ;)

it also works in the opposite direction - you can save a SpreadSheetDocument to an XLS file using

TableDoc.Write ("FileName", SpreadsheetDocumentFileType.XLSX);

use the Syntax Help on "SpreadsheetDocumentFileType: type to view all file formats

 
Subscribe