\ufeff (BOM) and sep=;\n stopped working in office 365 Excel? I am trying to open a .csv file separated by ";" and to inform the BOM togheter. Have any soluction?

Anônima
2023-04-17T19:55:58+00:00

Hello, I am creating a .csv file with content = "\UFEFF" + "SEP=|\n" + information.

But the excel cant available the BOM ("\UFEFF").

Any, solution?

Links of one issue equals.... but in XLS. https://stackoverflow.com/questions/20395699/sep-statement-breaks-utf8-bom-in-csv-file-which-is-generated-by-xsl

Att.,

Samuel Mesquita

Microsoft 365 e Office | Excel | Para empresas | Windows

Pergunta bloqueada. Essa pergunta foi migrada da Comunidade de Suporte da Microsoft. É possível votar se é útil, mas não é possível adicionar comentários ou respostas ou seguir a pergunta.

0 comentários Sem comentários

4 respostas

Classificar por: Mais útil
  1. Anônima
    2023-04-20T13:35:15+00:00

    Hello again...

    I would like to remind you, I am trying to create a file .csv that will open by a user final after downloading it. However, I would like the user to not care what culture and have special characters formatted correctly.

    I followed your steps ( print of notepade++), and I modified the information to put special characters "éà":

    but the result continues to be inconvenient, look

    The character ";" is the default separator to culture pt-br, how my excel is US, then happens it.

    How do I build the .csv to solve this issue?

    Esta resposta foi útil?

    0 comentários Sem comentários
  2. Dio Xavier 298.3K Pontos de reputação Moderador Voluntário
    2023-04-19T22:21:22+00:00

    The BOM (Byte Order Mark) and the "sep=;" syntax are still supported in Office 365 Excel. However, there are some limitations and issues that you may encounter.

    One issue is that Excel may not recognize the BOM if it is not the first character in the file. To ensure that the BOM is properly recognized, you can add a blank line at the beginning of the file and place the BOM on the second line. Here is an example of a properly formatted CSV file:

    -- blank line -- <br>sep=; <br>col1;col2;col3 <br>value1;value2;value3 <br>value4;value5;value6

    Note that the BOM is encoded as  (a zero-width no-break space) and the "sep=;" syntax is on the second line.

    To open this file in Excel using VBA, you can use the following code:

    Sub OpenCSV() <br> Dim filename As String <br> Dim wb As Workbook <br> Dim ws As Worksheet <br> <br> filename = "file.csv" <br> <br> Set wb = Workbooks.Open(filename, Local:=True) <br> <br> ' Get the first worksheet in the workbook <br> Set ws = wb.Sheets(1) <br> <br> ' Do something with the data in the worksheet <br> <br> ' Close the workbook without saving changes <br> wb.Close SaveChanges:=False <br>End Sub

    This code opens the CSV file as a workbook and gets the first worksheet in the workbook. You can then use the worksheet object to read and manipulate the data as needed. Finally, the code closes the workbook without saving changes.

    Note that the "Local:=True" argument is used to ensure that Excel recognizes the "sep=;" syntax and correctly separates the columns in the worksheet. Without this argument, Excel may use the default delimiter (comma) and not properly separate the columns.

    Esta resposta foi útil?

    0 comentários Sem comentários
  3. Anônima
    2023-04-19T19:35:54+00:00

    This solution not work in angular applications, See:

    import FileSaver from 'file-saver';

    let textToConvert = 'éà|ça|12\nà@€|çï|13\n';

        const fileName = 'example.csv';

    const blob = new Blob(['\ufeff' + 'SEP=|',textToConvert], { type: "text/csv;charset=utf-8-sig;" });

    FileSaver(blob, fileName);

    Case code 'SEP=|\n' Observe "\n" :

    import FileSaver from 'file-saver';

    let textToConvert = 'éà|ça|12\nà@€|çï|13\n';

        const fileName = 'example.csv';

    const blob = new Blob(['\ufeff' + 'SEP=|\n',textToConvert], { type: "text/csv;charset=utf-8-sig;" });

    FileSaver(blob, fileName);

    Now, with "\t":

    import FileSaver from 'file-saver';

    let textToConvert = 'éà\tça\t12\nà@€\tçï\t13\n';

        const fileName = 'example.csv';

    const blob = new Blob(['\ufeff',textToConvert], { type: "text/csv;charset=utf-8-sig;" });

    FileSaver(blob, fileName);

    The problem continue, I need help with it. The final user should open document without care what culture is.

    Esta resposta foi útil?

    0 comentários Sem comentários
  4. Dio Xavier 298.3K Pontos de reputação Moderador Voluntário
    2023-04-17T21:30:58+00:00

    Hello

    Welcome to Microsoft 365 and Office.

    Yes, you can try a few different solutions to include the BOM (Byte Order Mark) in your CSV file when opening it in Excel.

    1. Use UTF-8 encoding with BOM: When creating your CSV file, save it using the UTF-8 encoding with BOM. This can typically be done through the options in your programming language or text editor. The BOM character for UTF-8 is "\uFEFF". Here's an example of how you can create a CSV file with UTF-8 encoding and BOM using Python:
    *import csvwith open('file.csv', mode='w', encoding='utf-8-sig', newline='') as file: writer = csv.writer(file, delimiter=';') # Write the BOM character followed by your content writer.writerow(['\ufeff' + 'SEP= ', 'information'])* <br> ---

    The utf-8-sig encoding ensures that the BOM is included in the resulting file.

    1. Use a different delimiter: Instead of using the standard comma (",") or semicolon (";") as a delimiter, you can use a different character that is unlikely to appear in your data, such as a tab ("\t"). This way, you won't need to include the BOM to indicate the separator, and Excel will open the file correctly.
    2. Manually insert BOM in the text editor: If you have already created the CSV file without the BOM, you can open it in a text editor that supports inserting special characters, and manually insert the BOM at the beginning of the file. Save the file after inserting the BOM, and then try opening it in Excel.

    It's worth noting that some versions of Excel may still have issues with properly interpreting the BOM in a CSV file. If you're encountering problems, you may need to use one of the other solutions mentioned above or consider using a different file format, such as Excel's native .xlsx format, which doesn't require the use of a BOM.

    Esta resposta foi útil?

    0 comentários Sem comentários