Progress
<div class="xblock xblock-public_view xblock-public_view-vertical" data-graded="False" data-has-score="False" data-runtime-class="LmsRuntime" data-init="VerticalStudentView" data-course-id="course-v1:1C+WwLF+2025_T1" data-request-token="dc90f9b898aa11f0b655021fb1909faa" data-runtime-version="1" data-usage-id="block-v1:1C+WwLF+2025_T1+type@vertical+block@7c758d00369b4f43bd7f900fba01e36b" data-block-type="vertical">
<h2 class="hd hd-2 unit-title">Reading CSV Files</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:1C+WwLF+2025_T1+type@html+block@43b27f92d4574bbbac67e8be6428eb59">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlModule" data-graded="False" data-has-score="False" data-runtime-class="LmsRuntime" data-init="XBlockToXModuleShim" data-block-type="html" data-request-token="dc90f9b898aa11f0b655021fb1909faa" data-runtime-version="1" data-usage-id="block-v1:1C+WwLF+2025_T1+type@html+block@43b27f92d4574bbbac67e8be6428eb59" data-type="HTMLModule" data-course-id="course-v1:1C+WwLF+2025_T1">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p class="MsoNormal" align="center" style="text-align:center"><b style="mso-bidi-font-weight:
normal"><span lang="EN-US" style="font-size:18.0pt;line-height:107%">Reading CSV Files<o:p></o:p></span></b></p>
<p class="MsoNormal"><span lang="EN-US">CSV is another file format we will read in the 1C:Enterprise platform.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">In fact, CSV is the same text format as TXT and can be opened in a regular notepad, so we will use exactly the same methods for CSV as for TXT. Let us change the content of our file by adding a CSV abbreviation at the beginning of each line so we do not confuse the data. (Fig. 1):<o:p></o:p></span></p>
<p class="MsoNormal" align="center" style="text-align:center"><span lang="EN-US"><img height="357" width="430" src="/assets/courseware/v1/cc026cf2da1056631cd07aac8023eef1/asset-v1:1C+WwLF+2025_T1+type@asset+block/ok_07__Reading_CSV_Files_1.jpg" alt="" /><br /> (Fig. 1)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Now, let us add to our module the data read functionality and improve the readability of our code:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:#804040">&AtClient</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">Procedure</span></b><span lang="EN-US" style="font-size:
10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:black"> </span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";
mso-fareast-font-family:"Courier New";color:blue">ReadTheFile</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:red">(</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:blue">Command</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">)</span></b><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><span style="mso-spacerun:yes"> </span><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><span style="mso-spacerun:yes"> </span></span><span lang="EN-US" style="font-size:
10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:blue">Object</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">.</span></b><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:blue">ExternalFileData</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:red">.</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:blue">Clear</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">();</span></b><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:black"><span style="mso-spacerun:yes"> </span><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><span style="mso-spacerun:yes"> </span><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><span style="mso-spacerun:yes"> </span></span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">If</span></b><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:black"> </span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:blue">Object</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">.</span></b><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:blue">FileType</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:black"> </span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">=</span></b><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:black"> "TXT" </span><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:#804040">OR</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:black"> </span><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:blue">Object</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:red">.</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:blue">FileType</span><span lang="EN-US" style="font-size:
10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:black"> </span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:red">=</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"> "CSV" </span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:red">Then</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><span style="mso-spacerun:yes"> </span></span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:blue">ReadTXT_CSV</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">();</span></b><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><span style="mso-spacerun:yes"> </span></span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">EndIf;</span></b><span lang="EN-US" style="font-size:
10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:black"><span style="mso-spacerun:yes"> </span><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><span style="mso-spacerun:yes"> </span><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">EndProcedure</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:
"Courier New";mso-fareast-font-family:"Courier New";color:#804040">&AtClient</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;background:white"><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:
"Courier New";color:red">Procedure</span></b><span lang="EN-US" style="font-size:
10.0pt;font-family:"Courier New";mso-fareast-font-family:"Courier New";
color:black"> </span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";
mso-fareast-font-family:"Courier New";color:blue">ReadTXT_CSV</span><b style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:10.0pt;
font-family:"Courier New";mso-fareast-font-family:"Courier New";color:red">()</span></b><span lang="EN-US" style="font-size:12.0pt;font-family:"Times New Roman",serif;
mso-fareast-font-family:"Times New Roman""><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">We simply want to place all the methods for processing different formats outside of the main command <i style="mso-bidi-font-style:
normal">ReadFile(Command)</i> so that you can trigger them depending on the specified data type.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">As we did not have to change the code, we simply start the session and read the CSV file (Fig. 2):<o:p></o:p></span></p>
<p class="MsoNormal" align="center" style="text-align:center"><span lang="EN-US"><img height="539" width="623" src="/assets/courseware/v1/0b842463cc6cff31e929d5ad8de5dd56/asset-v1:1C+WwLF+2025_T1+type@asset+block/ok_07__Reading_CSV_Files_2.jpg" alt="" /><br /> (Fig. 2)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">It works!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Please note that when you create a CSV file, you can use various separators, quotes ("), and other special characters. They determine how the data is processed but not how it is read.<o:p></o:p></span></p>
</div>
</div>
</div>
</div>