Is there a way to get Excel content as HTML/Text like Word add-in?












1















I have used a sample Excel code to get excel using an add-in:



async function run() {
try {
await Excel.run(async context => {

// const range = context.workbook.getSelectedRange();

const sheetName = 'Sheet1';
const rangeAddress = 'F1:F20';
const worksheet = context.workbook.worksheets.getItem(sheetName);
const range = worksheet.getRange(rangeAddress);
range.load('text');

await context.sync();
console.log(range.text);
});
} catch(error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
};
}


Here it gives you an array of data for F column in excel.



Isn't there a way to get the whole worksheet as HTML or Text like what we do in Word add-in:



// Run a batch operation against the Word object model.
Word.run(function (context) {

// Create a proxy object for the document body.
var body = context.document.body;

// Queue a commmand to get the HTML contents of the body.
var bodyHTML = body.getHtml();

// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log("Body HTML contents: " + bodyHTML.value);
});
})
.catch(function (error) {
console.log("Error: " + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});


I appreciate if someone could shed some light on this issue.










share|improve this question

























  • How do you envision this should look? Word's content is stored left-to-right, top-to-bottom which is pretty straight-forward for getting the content in these format. Excel's content is essentially a matrix, which is best reflected as an array. The array can be processed to any format you prefer...?

    – Cindy Meister
    Jan 10 at 16:58











  • @CindyMeister, well at least something like Google sheets to export it as a PDF. And the structure can be pretty much like it is shown in Excel, but without borders.

    – ALH
    Jan 12 at 12:09
















1















I have used a sample Excel code to get excel using an add-in:



async function run() {
try {
await Excel.run(async context => {

// const range = context.workbook.getSelectedRange();

const sheetName = 'Sheet1';
const rangeAddress = 'F1:F20';
const worksheet = context.workbook.worksheets.getItem(sheetName);
const range = worksheet.getRange(rangeAddress);
range.load('text');

await context.sync();
console.log(range.text);
});
} catch(error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
};
}


Here it gives you an array of data for F column in excel.



Isn't there a way to get the whole worksheet as HTML or Text like what we do in Word add-in:



// Run a batch operation against the Word object model.
Word.run(function (context) {

// Create a proxy object for the document body.
var body = context.document.body;

// Queue a commmand to get the HTML contents of the body.
var bodyHTML = body.getHtml();

// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log("Body HTML contents: " + bodyHTML.value);
});
})
.catch(function (error) {
console.log("Error: " + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});


I appreciate if someone could shed some light on this issue.










share|improve this question

























  • How do you envision this should look? Word's content is stored left-to-right, top-to-bottom which is pretty straight-forward for getting the content in these format. Excel's content is essentially a matrix, which is best reflected as an array. The array can be processed to any format you prefer...?

    – Cindy Meister
    Jan 10 at 16:58











  • @CindyMeister, well at least something like Google sheets to export it as a PDF. And the structure can be pretty much like it is shown in Excel, but without borders.

    – ALH
    Jan 12 at 12:09














1












1








1


2






I have used a sample Excel code to get excel using an add-in:



async function run() {
try {
await Excel.run(async context => {

// const range = context.workbook.getSelectedRange();

const sheetName = 'Sheet1';
const rangeAddress = 'F1:F20';
const worksheet = context.workbook.worksheets.getItem(sheetName);
const range = worksheet.getRange(rangeAddress);
range.load('text');

await context.sync();
console.log(range.text);
});
} catch(error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
};
}


Here it gives you an array of data for F column in excel.



Isn't there a way to get the whole worksheet as HTML or Text like what we do in Word add-in:



// Run a batch operation against the Word object model.
Word.run(function (context) {

// Create a proxy object for the document body.
var body = context.document.body;

// Queue a commmand to get the HTML contents of the body.
var bodyHTML = body.getHtml();

// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log("Body HTML contents: " + bodyHTML.value);
});
})
.catch(function (error) {
console.log("Error: " + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});


I appreciate if someone could shed some light on this issue.










share|improve this question
















I have used a sample Excel code to get excel using an add-in:



async function run() {
try {
await Excel.run(async context => {

// const range = context.workbook.getSelectedRange();

const sheetName = 'Sheet1';
const rangeAddress = 'F1:F20';
const worksheet = context.workbook.worksheets.getItem(sheetName);
const range = worksheet.getRange(rangeAddress);
range.load('text');

await context.sync();
console.log(range.text);
});
} catch(error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
};
}


Here it gives you an array of data for F column in excel.



Isn't there a way to get the whole worksheet as HTML or Text like what we do in Word add-in:



// Run a batch operation against the Word object model.
Word.run(function (context) {

// Create a proxy object for the document body.
var body = context.document.body;

// Queue a commmand to get the HTML contents of the body.
var bodyHTML = body.getHtml();

// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log("Body HTML contents: " + bodyHTML.value);
});
})
.catch(function (error) {
console.log("Error: " + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});


I appreciate if someone could shed some light on this issue.







jquery office-js excel-addins






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 10 at 16:56









Cindy Meister

15.8k102437




15.8k102437










asked Jan 2 at 11:06









ALHALH

2,21443079




2,21443079













  • How do you envision this should look? Word's content is stored left-to-right, top-to-bottom which is pretty straight-forward for getting the content in these format. Excel's content is essentially a matrix, which is best reflected as an array. The array can be processed to any format you prefer...?

    – Cindy Meister
    Jan 10 at 16:58











  • @CindyMeister, well at least something like Google sheets to export it as a PDF. And the structure can be pretty much like it is shown in Excel, but without borders.

    – ALH
    Jan 12 at 12:09



















  • How do you envision this should look? Word's content is stored left-to-right, top-to-bottom which is pretty straight-forward for getting the content in these format. Excel's content is essentially a matrix, which is best reflected as an array. The array can be processed to any format you prefer...?

    – Cindy Meister
    Jan 10 at 16:58











  • @CindyMeister, well at least something like Google sheets to export it as a PDF. And the structure can be pretty much like it is shown in Excel, but without borders.

    – ALH
    Jan 12 at 12:09

















How do you envision this should look? Word's content is stored left-to-right, top-to-bottom which is pretty straight-forward for getting the content in these format. Excel's content is essentially a matrix, which is best reflected as an array. The array can be processed to any format you prefer...?

– Cindy Meister
Jan 10 at 16:58





How do you envision this should look? Word's content is stored left-to-right, top-to-bottom which is pretty straight-forward for getting the content in these format. Excel's content is essentially a matrix, which is best reflected as an array. The array can be processed to any format you prefer...?

– Cindy Meister
Jan 10 at 16:58













@CindyMeister, well at least something like Google sheets to export it as a PDF. And the structure can be pretty much like it is shown in Excel, but without borders.

– ALH
Jan 12 at 12:09





@CindyMeister, well at least something like Google sheets to export it as a PDF. And the structure can be pretty much like it is shown in Excel, but without borders.

– ALH
Jan 12 at 12:09












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005195%2fis-there-a-way-to-get-excel-content-as-html-text-like-word-add-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005195%2fis-there-a-way-to-get-excel-content-as-html-text-like-word-add-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The term 'EXEC' is not recognized as the name of a cmdlet Powershell

NPM command prompt closes immediately [closed]

Error binding properties and functions in emscripten