Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

533
Visualizações
Copying text that can be pasted as a table in word, excel, etc

I'm not sure if this is considered converting the text data to rich text or not, but I want to take a series of inputs, either from a table or a series of divs (the latter is what I'm using), and place it into a format that can be easily pasted into Word, Outlook or Excel as a table.

I haven't figured out how I'm going to cycle through the list to get all possible entries just yet, but in pseudo code, the following is what I'm looking to do:

var currentLine;    // This is the current line used in the following loop:
for (<each list item found>) {
    currentLine = `${box1A} ${box1B}`;
    <append currentLine to a new line in a textarea element>;
}
<select the text in the textarea element>;
document.execCommand('copy');

Ultimately, the javascript that I will actually use will result in new lines being pasted into a new row (this is good), however, the two strings will be in the came cell. See the following example:

+------------+-------+
| box1A box1B|       |
+------------+-------+
| box2A box2B|       |
+------------+-------+
| box3A box3B|       |
+------------+-------+
| etc.. etc..|       |
+------------+-------+

How can I ensure that box1A will end up being in one cell, and box1B will automatically be pasted into a second cell on the same row? See the following example of what I want:

+-------+-------+
| box1A | box1B |
+-------+-------+
| box2A | box2B |
+-------+-------+
| box3A | box3B |
+-------+-------+
| etc.. | etc.. |
+-------+-------+
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

From my findings so far, values are separated by tabs. In the example I provided, in order for boxA and boxB to align to different cells on the same row, you can use the following setup for the string:

var row = `${box1A}\t${box1B}\n${box2A}\t${box2B}\n${box3A}\t${box3B}`

The end result of the above line would yield, once copied onto the clipboard & pasted into Excel:

+-------+-------+
| box1A | box1B |
+-------+-------+
| box2A | box2B |
+-------+-------+
| box3A | box3B |
+-------+-------+

The \t denotes a Horizontal Tabulator, and will result in automatically entering the next value into the next cell.

The \n denotes a New Line, and will result in automatically entering the next value into the next cell.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda